Received: by 10.223.185.116 with SMTP id b49csp1044429wrg; Fri, 16 Feb 2018 11:23:00 -0800 (PST) X-Google-Smtp-Source: AH8x224e6sQvHeFlM0GOxmdJzlxYDSei91YB7y7rlsvdZKlfuuXE+8kyDu4GlaAiKgPzIo9tH8cJ X-Received: by 10.101.77.195 with SMTP id q3mr5866243pgt.395.1518808980279; Fri, 16 Feb 2018 11:23:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518808980; cv=none; d=google.com; s=arc-20160816; b=UI6qScPmXGOjkUcNjsDR6mw0Q6lhMs97+ViN9jq6o0WtYJOip4C/uwC825ubBc7UHe UvURfnSIEM3gkf5YHGxwod9z98fsvf4FJV8MRaZRlPgN7Y7OfDVk/Elut2gVoRdXqRVB jjzX2sbF2WzMyfXAtFGLlppBSLBljNr37gIaCiVwR92rsq6gJMyLjtbvBZ4sRBIjYMka rmJdNRfIcoOx/6Gs33MKBF76hS3Tw0rqT69MJapyG+MCwcLLWzpdBt410Y4vV/snQFP0 +/HbcOJVCsd/MKchNwKi9n+Eqwli64909b0kQktWhGhH+OY+L+ms3Hvtjx6bb+CDpWFx 4VmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=gYrtd/F9CU+eEKPWSZwqQLag/iQW4L2ns27WjK41yaQ=; b=e5DgJ7l4lD3lAGEfNTXxNhjQJvf9qPuiPUZ6oCF3EG+24E98+uK86M6b5ssEraM1tN PhAYQ3T1EyhqreWEzgJ/lTeKcrdrFBpw0gXVaXxlRyIsNMa+jiYGgTN58gVM591yIiiI bDcU6h+++nL2GeBZvqkqYi4wqqYLyIYE3Aq4ZuAEqMJYgfEcDmKvG7/EZVmAkDvGLeVl 98S3tDwljwiS4aJXna91yw0vW75yDH75K7RtJl7xP6Scq3lx9Mh2hCtcE8SFnXR5dD1Y rpLr3vuRYR9X6Oj3lqjnnNYJfAvhtvk25LK8y5wFjwZp5j4dmuyfsb1nbDsMmww7EJga 6ylg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=m35jHujk; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h32-v6si3240907pld.217.2018.02.16.11.22.45; Fri, 16 Feb 2018 11:23:00 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=m35jHujk; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1162867AbeBPSKH (ORCPT + 99 others); Fri, 16 Feb 2018 13:10:07 -0500 Received: from mail-it0-f65.google.com ([209.85.214.65]:34991 "EHLO mail-it0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1162415AbeBPSKG (ORCPT ); Fri, 16 Feb 2018 13:10:06 -0500 Received: by mail-it0-f65.google.com with SMTP id v194so2348407itb.0 for ; Fri, 16 Feb 2018 10:10:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=gYrtd/F9CU+eEKPWSZwqQLag/iQW4L2ns27WjK41yaQ=; b=m35jHujkzsSSJQ9A3hmhjzfctPNpRTjolc0bHeXpMDuMF1UkNtJWO8NDeIH5irLN7u DxKEDHxkiBsKs2ilqZUsRobx3qlGEI0d1UNIal/+K2OqV+ycCFv352MQ/tHRGk8KzP/4 vlntfKCs8wNVeyAnSE1upXT4aeZg+ZvyAMmcK9masF7F8X29UnCwEDL34X/aZbnZDpIg /syrbgaD9X6On+dFTFXQg6851k7ZxEtW8ZYwzBBJoSOTCh2VgoLU9BVkJV6m7+G1YPFz nvFK7umPvLYVkgUnKayAumFpveIWnN+f/O9fc84LfFZ7fryeT/C8la6UMeF8rS7vGN/y FEvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=gYrtd/F9CU+eEKPWSZwqQLag/iQW4L2ns27WjK41yaQ=; b=j+Fc5yO6P5Ticrn7B45qg6Yww8ANN6IDaeBU4GG77nG8VaTa83zioiaJv2txdb4gAq keIH7rpTbfAiYNhuSHZQFvmuH17sc3cNuQYRP8DjzJ9jHfdTC8SSi88Azx0oJQZZUd0+ aMsqX1SuXTJIexk1AJ6xxjVYrJl4tvc8Mvu9qsgeghAK5sdYATav7ZI+1blT3Yt0TDC7 b6Jon589wEFi/gyWA8V9mfvp30Cx/Y8T8MM3DggpfSNCSIafu0sYkEur9zkjTQBCjC8x sO+HAZjPdxninzyi3rILgZTrblVRFDfG1xe+uNY1+gxkZtc9GPpgBy8ncOVm6QHSY7/K PyIw== X-Gm-Message-State: APf1xPC01J3Qvpmd1/QXUy4pbBNGHCKzd+iaMN2MRu4HTXpqRMr4ldro T2CDtw8NXz0tYCFQPeX/aMY= X-Received: by 10.36.144.68 with SMTP id x65mr8957038itd.60.1518804605780; Fri, 16 Feb 2018 10:10:05 -0800 (PST) Received: from localhost (172-220-001-224.dhcp.chtrptr.net. [172.220.1.224]) by smtp.gmail.com with ESMTPSA id m5sm16963142iti.2.2018.02.16.10.10.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Feb 2018 10:10:05 -0800 (PST) Date: Fri, 16 Feb 2018 12:09:58 -0600 From: Dennis Zhou To: Tejun Heo , Christoph Lameter Cc: Daniel Borkmann , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/3] percpu: allow select gfp to be passed to underlying allocators Message-ID: <20180216180958.GB81034@localhost> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The prior patch added support for passing gfp flags through to the underlying allocators. This patch allows users to pass along gfp flags (currently only __GFP_NORETRY and __GFP_NOWARN) to the underlying allocators. This should allow users to decide if they are ok with failing allocations recovering in a more graceful way. Additionally, gfp passing was done as additional flags in the previous patch. Instead, change this to caller passed semantics. GFP_KERNEL is also removed as the default flag. It continues to be used for internally caused underlying percpu allocations. V2: Removed gfp_percpu_mask in favor of doing it inline. Removed GFP_KERNEL as a default flag for __alloc_percpu_gfp. Signed-off-by: Dennis Zhou Suggested-by: Daniel Borkmann --- mm/percpu-km.c | 2 +- mm/percpu-vm.c | 4 ++-- mm/percpu.c | 16 +++++++--------- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/mm/percpu-km.c b/mm/percpu-km.c index 0d88d7b..38de70a 100644 --- a/mm/percpu-km.c +++ b/mm/percpu-km.c @@ -56,7 +56,7 @@ static struct pcpu_chunk *pcpu_create_chunk(gfp_t gfp) if (!chunk) return NULL; - pages = alloc_pages(gfp | GFP_KERNEL, order_base_2(nr_pages)); + pages = alloc_pages(gfp, order_base_2(nr_pages)); if (!pages) { pcpu_free_chunk(chunk); return NULL; diff --git a/mm/percpu-vm.c b/mm/percpu-vm.c index 0af71eb..d8078de 100644 --- a/mm/percpu-vm.c +++ b/mm/percpu-vm.c @@ -37,7 +37,7 @@ static struct page **pcpu_get_pages(void) lockdep_assert_held(&pcpu_alloc_mutex); if (!pages) - pages = pcpu_mem_zalloc(pages_size, 0); + pages = pcpu_mem_zalloc(pages_size, GFP_KERNEL); return pages; } @@ -86,7 +86,7 @@ static int pcpu_alloc_pages(struct pcpu_chunk *chunk, unsigned int cpu, tcpu; int i; - gfp |= GFP_KERNEL | __GFP_HIGHMEM; + gfp |= __GFP_HIGHMEM; for_each_possible_cpu(cpu) { for (i = page_start; i < page_end; i++) { diff --git a/mm/percpu.c b/mm/percpu.c index f97443d..fa3f854 100644 --- a/mm/percpu.c +++ b/mm/percpu.c @@ -454,9 +454,6 @@ static void pcpu_next_fit_region(struct pcpu_chunk *chunk, int alloc_bits, * This is to facilitate passing through whitelisted flags. The * returned memory is always zeroed. * - * CONTEXT: - * Does GFP_KERNEL allocation. - * * RETURNS: * Pointer to the allocated area on success, NULL on failure. */ @@ -466,10 +463,9 @@ static void *pcpu_mem_zalloc(size_t size, gfp_t gfp) return NULL; if (size <= PAGE_SIZE) - return kzalloc(size, gfp | GFP_KERNEL); + return kzalloc(size, gfp); else - return __vmalloc(size, gfp | GFP_KERNEL | __GFP_ZERO, - PAGE_KERNEL); + return __vmalloc(size, gfp | __GFP_ZERO, PAGE_KERNEL); } /** @@ -1344,6 +1340,8 @@ static struct pcpu_chunk *pcpu_chunk_addr_search(void *addr) static void __percpu *pcpu_alloc(size_t size, size_t align, bool reserved, gfp_t gfp) { + /* whitelisted flags that can be passed to the backing allocators */ + gfp_t pcpu_gfp = gfp & (GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN); bool is_atomic = (gfp & GFP_KERNEL) != GFP_KERNEL; bool do_warn = !(gfp & __GFP_NOWARN); static int warn_limit = 10; @@ -1426,7 +1424,7 @@ static void __percpu *pcpu_alloc(size_t size, size_t align, bool reserved, } if (list_empty(&pcpu_slot[pcpu_nr_slots - 1])) { - chunk = pcpu_create_chunk(0); + chunk = pcpu_create_chunk(pcpu_gfp); if (!chunk) { err = "failed to allocate new chunk"; goto fail; @@ -1455,7 +1453,7 @@ static void __percpu *pcpu_alloc(size_t size, size_t align, bool reserved, page_start, page_end) { WARN_ON(chunk->immutable); - ret = pcpu_populate_chunk(chunk, rs, re, 0); + ret = pcpu_populate_chunk(chunk, rs, re, pcpu_gfp); spin_lock_irqsave(&pcpu_lock, flags); if (ret) { @@ -1576,7 +1574,7 @@ void __percpu *__alloc_reserved_percpu(size_t size, size_t align) static void pcpu_balance_workfn(struct work_struct *work) { /* gfp flags passed to underlying allocators */ - const gfp_t gfp = __GFP_NORETRY | __GFP_NOWARN; + const gfp_t gfp = GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN; LIST_HEAD(to_free); struct list_head *free_head = &pcpu_slot[pcpu_nr_slots - 1]; struct pcpu_chunk *chunk, *next; -- 1.8.3.1