New issue
Advanced search Search tips

Issue 657213 link

Starred by 1 user

Issue metadata

Status: Fixed
Owner:
Closed: Nov 2016
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 3
Type: Bug



Sign in to add a comment

Consider reducing scope of temp allocation to minimize peak memory usage

Project Member Reported by stanisc@chromium.org, Oct 19 2016

Issue description

Here is the pattern I observed in gles2_cmd_decoder.cc and elsewhere:

// 1) Allocate (and zero) a temp buffer
    std::unique_ptr<char[]> zero(new char[pixels_size]);
    memset(zero.get(), 0, pixels_size);

// 2) Use the zero buffer to populate a texture
    glTexImage2D(target, level, TextureManager::AdjustTexInternalFormat(
                                    feature_info_.get(), internal_format),
                 width, height, border, format, type, zero.get());

// 3) Do a bunch of other stuff that doesn't need the |zero| buffer.
    if (!src.IsEmpty()) {
      GLint destX = src.x() - x;
      GLint destY = src.y() - y;
      if (requires_luma_blit) {
        copy_tex_image_blit_->DoCopyTexSubImageToLUMACompatibilityTexture(
            this, texture->service_id(), texture->target(), target, format,
            type, level, destX, destY, 0,
            src.x(), src.y(), src.width(), src.height(),
            GetBoundReadFramebufferServiceId(),
            GetBoundReadFramebufferInternalFormat());
      } else {
        glCopyTexSubImage2D(target, level, destX, destY,
                            src.x(), src.y(), src.width(), src.height());
      }
    }

The temporary buffer remains on the heap for longer than necessary so other allocations could be made on top of it on the current thread or on any different thread. This increases memory pressure more than necessary.
Consider freeing the buffer immediately after its last usage.
It might be even cleaner to use a some sort of a "zero memory" class that could be passed directly to glTexImage2D and destroyed at the end of the call e.g.

    glTexImage2D(..., ZeroBuffer(pixels_size).data());

Look for std::unique_ptr<char[]> or std::unique_ptr<int8_t[]> for more instances of this pattern.
 
Status: Assigned (was: Untriaged)
Owner: chengx@chromium.org
Project Member

Comment 3 by bugdroid1@chromium.org, Nov 11 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/0643d7f805b69c2fd595540791dc6a62ca195254

commit 0643d7f805b69c2fd595540791dc6a62ca195254
Author: chengx <chengx@chromium.org>
Date: Fri Nov 11 02:17:13 2016

Reduce unique_ptr scope to save memory

There are a few functions where unique_ptrs are used but not destroyed right after their usage.
This will increase the peak memory usage.
Added extra scopes around these unique-ptrs to destroy them right after their usage.

BUG= 657213 
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel

Review-Url: https://codereview.chromium.org/2490553004
Cr-Commit-Position: refs/heads/master@{#431464}

[modify] https://crrev.com/0643d7f805b69c2fd595540791dc6a62ca195254/gpu/command_buffer/service/gles2_cmd_decoder.cc

Comment 4 by chengx@chromium.org, Nov 14 2016

Status: Fixed (was: Assigned)

Sign in to add a comment