Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4141185imm; Tue, 29 May 2018 23:14:25 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJVfMVAmvAiD1db4YrriOzrNSMJz5rFg4Bs3C9EpOyQMVnAkmnrAc+LMU+H7g2JUn1hjDFL X-Received: by 2002:a62:fd12:: with SMTP id p18-v6mr1492643pfh.152.1527660865803; Tue, 29 May 2018 23:14:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527660865; cv=none; d=google.com; s=arc-20160816; b=dh24BXohn3SVliTCkzwpEj6yj/+9IOKwfwys1by1Gf5bqZvnh0G5Wg7rgFOqIRFgzo qd6kJ3R5rjRTYKyki+SQ3or5CDE46VZ4gLUDw+ESQxF2aQjt+3LCh2DWUSvA4Mf4gmFm IhfxD1sV8dANvijpCQP6/C9ZVjkMzaHycdauThkanJRNCimU6CQhXIB3yCofZMsUkxbs UVdzwxAD++N+pXCobJc5B4kTkQEDlLCncAdoxkDZ0DZNXKSDD1rAt0+5ZbeTWVJyf1pN D6SDrVhOOUlM1q3BjzkyMFMHfKmqZF/Hv8lRSdfpfmGlolPONF2jMM7wHZjVrxQbg6B5 JM+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references:message-id :in-reply-to:date:mime-version:dkim-signature :arc-authentication-results; bh=fiV9iJcQjxqap98CwFkr5BPL8x33fS1+9534pZZSVtY=; b=rt/hhj6FBEdGjC2AhuxiuwILwxMdIA+IsmfnZBmFdyh6j+x1JASW+cb/pPclSLBVx/ K5qjG6Lf5+4DWMZTRKGvzZr4CiYCmR/6v9vL1L0A6fycb2nSLP/mVg9tdw6f9+HAeB2a lWRxuQqolsYcssEEJAuPXNq0I5CyNcSqw9palVvyrF4mbA49erGAuoUD+kz406hlFuQI lMG1jzuD4Jc7U3Oa1JPyIA9t+K578yFgz1OQELaPn1QaXng6NLNq0YQ1ydgB8LdocjiS fxtVdLMCVMx0LEFcs+ZD7/s7Y+B4g5Iliabfng6FMATFA0O77zIaV436yTXSgfyMuOaa +a1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=fM3yjh0f; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a8-v6si36141233pln.349.2018.05.29.23.14.12; Tue, 29 May 2018 23:14:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=fM3yjh0f; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935893AbeE3GMZ (ORCPT + 99 others); Wed, 30 May 2018 02:12:25 -0400 Received: from mail-ua0-f202.google.com ([209.85.217.202]:40451 "EHLO mail-ua0-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935775AbeE3GMW (ORCPT ); Wed, 30 May 2018 02:12:22 -0400 Received: by mail-ua0-f202.google.com with SMTP id a25-v6so10947442uak.7 for ; Tue, 29 May 2018 23:12:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:date:in-reply-to:message-id:references:subject:from:to :cc; bh=fiV9iJcQjxqap98CwFkr5BPL8x33fS1+9534pZZSVtY=; b=fM3yjh0fk1iQjkJI3hzWgZUVBrNel6u3l+mJj3Ao9ecxEJaAM17rpVWJClbdgZqs30 jpsEeddCMjwLm65NXnz6OaJXbt2YMgUsuuIgZBKNIBYW3S7xRFMBuTT5svICLxZC2eE3 9eRmdi+zilGZIVbFrRspxEuMFxJ7kdC+sBocYo13CGkGXSO2VS1CVqU+Gy2aVob62hOG 9uwGtj3+5VbO62yKhZJtdyMG5HZo0DUz4PUhUi75Pl93NDgL/yNK3p6REeAm2dOnmRDb PgM9M/gmjpok4f1cuCRLZkCIovyrG8rDi7MheKIv5kcIFElaNk5vYk2v8vPLdGFfejH2 MrbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:date:in-reply-to:message-id :references:subject:from:to:cc; bh=fiV9iJcQjxqap98CwFkr5BPL8x33fS1+9534pZZSVtY=; b=bXGNAE0KnheT5BUte6v3Ty/Pafhrui8XcvfErQ8GtdEBKiwuVnYmuKi3yB/leFBkuc 7X0zB4kuppcANEGMx28T9xF7uQvp94CU6xcn3RP9YvvOByWj/2g8fHsYW2t24KGA7i9x hzLryZDQy8TRTDc4+7HxOy5YxkeIVxDSBgdnBc7rePsavtfVf7GytgnYbjVrseNVf24q 0cWQZp7Mpmd/yOIm37LBe7+Pi5XQbOX0bKV8uqttsSMMWY29V96t5uzuN0vYahyC3dUS 4DDULbylr/xEEKUt2V8f/u6AiKRcg3kvorShBY/6/75KRCplHQTIoiX2RWv5bUWqjVTv iFBw== X-Gm-Message-State: ALKqPwcQrTgTO0IpMO6YPR6euR9ziX5HnVfvLlXi02lB+hKqco1vUEF/ 5/urS2jlBrfvX9bd5/nilyfEk5f75ss/ MIME-Version: 1.0 X-Received: by 2002:ab0:50f8:: with SMTP id d53-v6mr301428uaa.88.1527660741660; Tue, 29 May 2018 23:12:21 -0700 (PDT) Date: Tue, 29 May 2018 23:12:12 -0700 In-Reply-To: <20180529025722.GA25784@bombadil.infradead.org> Message-Id: <20180530061212.84915-1-gthelen@google.com> References: <20180529025722.GA25784@bombadil.infradead.org> X-Mailer: git-send-email 2.17.0.921.gf22659ad46-goog Subject: [PATCH v2] mm: condense scan_control From: Greg Thelen To: Andrew Morton , Michal Hocko , Johannes Weiner , Matthew Wilcox Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Greg Thelen Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use smaller scan_control fields for order, priority, and reclaim_idx. Convert fields from int => s8. All easily fit within a byte: * allocation order range: 0..MAX_ORDER(64?) * priority range: 0..12(DEF_PRIORITY) * reclaim_idx range: 0..6(__MAX_NR_ZONES) Since commit 6538b8ea886e ("x86_64: expand kernel stack to 16K") x86_64 stack overflows are not an issue. But it's inefficient to use ints. Use s8 (signed byte) rather than u8 to allow for loops like: do { ... } while (--sc.priority >= 0); Add BUILD_BUG_ON to verify that s8 is capable of storing max values. This reduces sizeof(struct scan_control): * 96 => 80 bytes (x86_64) * 68 => 56 bytes (i386) scan_control structure field order is changed to utilize padding. After this patch there is 1 bit of scan_control padding. Signed-off-by: Greg Thelen Suggested-by: Matthew Wilcox --- mm/vmscan.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 9b697323a88c..42731faea306 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -65,12 +65,6 @@ struct scan_control { /* How many pages shrink_list() should reclaim */ unsigned long nr_to_reclaim; - /* This context's GFP mask */ - gfp_t gfp_mask; - - /* Allocation order */ - int order; - /* * Nodemask of nodes allowed by the caller. If NULL, all nodes * are scanned. @@ -83,12 +77,6 @@ struct scan_control { */ struct mem_cgroup *target_mem_cgroup; - /* Scan (total_size >> priority) pages at once */ - int priority; - - /* The highest zone to isolate pages for reclaim from */ - enum zone_type reclaim_idx; - /* Writepage batching in laptop mode; RECLAIM_WRITE */ unsigned int may_writepage:1; @@ -111,6 +99,18 @@ struct scan_control { /* One of the zones is ready for compaction */ unsigned int compaction_ready:1; + /* Allocation order */ + s8 order; + + /* Scan (total_size >> priority) pages at once */ + s8 priority; + + /* The highest zone to isolate pages for reclaim from */ + s8 reclaim_idx; + + /* This context's GFP mask */ + gfp_t gfp_mask; + /* Incremented by the number of inactive pages that were scanned */ unsigned long nr_scanned; @@ -3047,6 +3047,14 @@ unsigned long try_to_free_pages(struct zonelist *zonelist, int order, .may_swap = 1, }; + /* + * scan_control uses s8 fields for order, priority, and reclaim_idx. + * Confirm they are large enough for max values. + */ + BUILD_BUG_ON(MAX_ORDER > S8_MAX); + BUILD_BUG_ON(DEF_PRIORITY > S8_MAX); + BUILD_BUG_ON(MAX_NR_ZONES > S8_MAX); + /* * Do not enter reclaim if fatal signal was delivered while throttled. * 1 is returned so that the page allocator does not OOM kill at this -- 2.17.0.921.gf22659ad46-goog