Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dns-sd] Optimize memory usage of SRP client #8370

Merged
merged 4 commits into from
Jul 17, 2021

Conversation

Damian-Nordic
Copy link
Contributor

@Damian-Nordic Damian-Nordic commented Jul 14, 2021

Problem

Current method of allocating data for the SRP services is inefficient, especially once we enable commisionable node advertising for Thread devices which involves both very short and very long TXT entries. In such a case we would allocate N * max(TXT_VALUE_SIZE_i) instead of sum(TXT_VALUE_SIZE_i).

Change overview

Allocate all SRP service data from a single flat buffer instead of using an array of arrays. That way, less memory
is used when entries of the same kind differ in size.
Also, don't duplicate TXT entry keys as they are constants.

Testing

Tested manually using nRF Connect Lock Example. Verified that both operational and commissionable advertising (the latter is not yet enabled by default). work correctly.

Fixes: #8366

src/lib/mdns/Advertiser.h Outdated Show resolved Hide resolved
src/lib/mdns/Advertiser.h Outdated Show resolved Hide resolved
src/lib/support/FixedBufferAllocator.h Outdated Show resolved Hide resolved
Allocate all SRP service data from a single flat buffer
instead of using an array of arrays. That way, less memory
is used when entries of the same kind differ in size.

Also, don't duplicate TXT entry keys as they are constants.
@todo
Copy link

todo bot commented Jul 17, 2021

Switch to max(commissionable TXT key size, operational TXT key size) after optimizing memory usage

// TODO: Switch to max(commissionable TXT key size, operational TXT key size) after optimizing memory usage
static constexpr uint8_t kMaxDnsServiceTxtKeySize = Mdns::OperationalAdvertisingParameters::kTxtMaxKeySize;
#else
// Thread only supports operational discovery.
static constexpr uint8_t kMaxDnsServiceTxtEntriesNumber = Mdns::OperationalAdvertisingParameters::kTxtMaxNumber;
static constexpr uint8_t kMaxDnsServiceTxtValueSize = Mdns::OperationalAdvertisingParameters::kTxtMaxValueSize;
static constexpr uint8_t kMaxDnsServiceTxtKeySize = Mdns::OperationalAdvertisingParameters::kTxtMaxKeySize;
#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD_COMMISSIONABLE_DISCOVERY
DnsBrowseCallback mDnsBrowseCallback;


This comment was generated by todo based on a TODO comment in 0669837 in #8370. cc @Damian-Nordic.

@github-actions
Copy link

Size increase report for "gn_qpg-example-build" from 4ef1ead

File Section File VM
chip-qpg6100-lighting-example.out .text 32 32
chip-qpg6100-lighting-example.out .heap 0 8
chip-qpg6100-lighting-example.out .bss 0 -8
Full report output
BLOAT REPORT

Files found only in the build output:
    report.csv

Comparing ./master_artifact/chip-qpg6100-lighting-example.out.map and ./pull_artifact/chip-qpg6100-lighting-example.out.map:

BLOAT EXECUTION FAILED WITH CODE 1:
bloaty: unknown file type for file './pull_artifact/chip-qpg6100-lighting-example.out.map'

Comparing ./master_artifact/chip-qpg6100-lighting-example.out and ./pull_artifact/chip-qpg6100-lighting-example.out:

sections,vmsize,filesize
.debug_info,0,3808
.debug_line,0,1207
.debug_str,0,886
.debug_abbrev,0,679
.debug_loc,0,468
.strtab,0,296
.symtab,0,144
.debug_frame,0,140
.debug_aranges,0,64
.debug_ranges,0,64
.text,32,32
.heap,8,0
.bss,-8,0
[Unmapped],0,-32


@github-actions
Copy link

Size increase report for "esp32-example-build" from 4ef1ead

File Section File VM
chip-temperature-measurement-app.elf .flash.text 51 60
chip-all-clusters-app.elf .flash.text 16 16
chip-lock-app.elf .flash.text -64 -64
Full report output
BLOAT REPORT

Files found only in the build output:
    report.csv

Comparing ./master_artifact/chip-shell.elf and ./pull_artifact/chip-shell.elf:

sections,vmsize,filesize
.debug_str,0,52
.debug_info,0,36
.debug_loc,0,4

Comparing ./master_artifact/chip-persistent-storage.elf and ./pull_artifact/chip-persistent-storage.elf:

sections,vmsize,filesize

Comparing ./master_artifact/chip-temperature-measurement-app.elf and ./pull_artifact/chip-temperature-measurement-app.elf:

sections,vmsize,filesize
[Unmapped],0,4045
.debug_info,0,178
.debug_str,0,64
.flash.text,60,51
.debug_loc,0,-2
.debug_line,0,-8

Comparing ./master_artifact/chip-all-clusters-app.elf and ./pull_artifact/chip-all-clusters-app.elf:

sections,vmsize,filesize
.debug_info,0,250
.xt.lit._ZN4chip6System5Mutex6UnlockEv,0,128
.xt.lit._ZN4chip11DeviceLayer8Internal35GenericPlatformManagerImpl_FreeRTOSINS0_19PlatformManagerImplEE10_PostEventEPKNS0_15ChipDeviceEventE,0,80
.debug_str,0,59
.xt.prop._ZN4chip11DeviceLayer8Internal26GenericPlatformManagerImplINS0_19PlatformManagerImplEE14_InitChipStackEv,0,40
.flash.text,16,16
.debug_loc,0,-2
.debug_line,0,-7
.xt.prop._ZN4chip11DeviceLayer8Internal35GenericPlatformManagerImpl_FreeRTOSINS0_19PlatformManagerImplEE14_LockChipStackEv,0,-12
.xt.prop._ZN4chip11DeviceLayer8Internal35GenericPlatformManagerImpl_FreeRTOSINS0_19PlatformManagerImplEE15_StartChipTimerEj,0,-12
.xt.prop._ZN4chip11DeviceLayer8Internal35GenericPlatformManagerImpl_FreeRTOSINS0_19PlatformManagerImplEE16_UnlockChipStackEv,0,-12
[Unmapped],0,-16
.xt.lit._ZN4chip11DeviceLayer8Internal35GenericPlatformManagerImpl_FreeRTOSINS0_19PlatformManagerImplEE14_LockChipStackEv,0,-48
.xt.lit._ZN4chip11DeviceLayer8Internal35GenericPlatformManagerImpl_FreeRTOSINS0_19PlatformManagerImplEE15_StartChipTimerEj,0,-48
.xt.lit._ZN4chip11DeviceLayer8Internal35GenericPlatformManagerImpl_FreeRTOSINS0_19PlatformManagerImplEE16_UnlockChipStackEv,0,-48
.xt.prop._ZN4chip6System5Mutex6UnlockEv,0,-108

Comparing ./master_artifact/chip-lock-app.elf and ./pull_artifact/chip-lock-app.elf:

sections,vmsize,filesize
.debug_info,0,266
.debug_str,0,175
[Unmapped],0,64
.debug_loc,0,-2
.debug_line,0,-7
.flash.text,-64,-64

Comparing ./master_artifact/chip-pigweed-app.elf and ./pull_artifact/chip-pigweed-app.elf:

sections,vmsize,filesize


@github-actions
Copy link

Size increase report for "nrfconnect-example-build" from 4ef1ead

File Section File VM
chip-shell.elf device_handles -4 -4
chip-shell.elf [LOAD #3 [RW]] 0 -23
chip-shell.elf text -60 -60
chip-shell.elf bss 0 -233
chip-lock.elf [LOAD #3 [RW]] 0 19
chip-lock.elf device_handles 8 8
chip-lock.elf text -56 -56
chip-lock.elf bss 0 -243
Full report output
BLOAT REPORT

Files found only in the build output:
    report.csv

Comparing ./master_artifact/chip-shell.elf and ./pull_artifact/chip-shell.elf:

sections,vmsize,filesize
.debug_info,0,3951
.debug_line,0,1059
.debug_str,0,853
.debug_abbrev,0,666
.debug_loc,0,419
.strtab,0,285
.symtab,0,144
.debug_frame,0,140
.debug_aranges,0,64
.debug_ranges,0,8
.shstrtab,0,-1
device_handles,-4,-4
[LOAD #3 [RW]],-23,0
text,-60,-60
bss,-233,0

Comparing ./master_artifact/chip-lock.elf and ./pull_artifact/chip-lock.elf:

sections,vmsize,filesize
.debug_info,0,3924
.debug_line,0,1062
.debug_str,0,853
.debug_abbrev,0,674
.debug_loc,0,427
.strtab,0,296
.symtab,0,144
.debug_frame,0,140
.debug_aranges,0,64
[LOAD #3 [RW]],19,0
.debug_ranges,0,8
device_handles,8,8
text,-56,-56
bss,-243,0


@Damian-Nordic Damian-Nordic merged commit 37df562 into project-chip:master Jul 17, 2021
nikita-s-wrk pushed a commit to nikita-s-wrk/connectedhomeip that referenced this pull request Sep 23, 2021
* [dns-sd] Optimize memory usage of SRP client

Allocate all SRP service data from a single flat buffer
instead of using an array of arrays. That way, less memory
is used when entries of the same kind differ in size.

Also, don't duplicate TXT entry keys as they are constants.

* Address code review comments

* Add TODO

* Restyled by clang-format

Co-authored-by: Restyled.io <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

use fixed buffer allocator to reduce the memory footprint from N*M to sum(M_i)
7 participants