Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2005159rwl; Thu, 30 Mar 2023 04:53:01 -0700 (PDT) X-Google-Smtp-Source: AKy350bTEWM3A7iiG8c1Pm9gf6AML+oBrzSbcb39Zub5PbOxOLDJrCqG+n2xYrKtQwz+1SNIkDIV X-Received: by 2002:a17:903:110c:b0:1a2:1e96:600d with SMTP id n12-20020a170903110c00b001a21e96600dmr2006421plh.2.1680177180759; Thu, 30 Mar 2023 04:53:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680177180; cv=none; d=google.com; s=arc-20160816; b=mUgf4B6KvDR8aZr+nSq9WVTfScayVQrMwGElQR6sLAjY7FsVE+KxO5h+t7X548iKPq L6NyJkdlZ3EM8xqxdQoxWDnmFzF0NbuZuMGxIzahCT36BOGioJWBi4YRygZtQJphBPUj TtbbML26f/KbIplzDLTZ+Gm/dR0s91caGI351Xy+SZNAzmp7Hh8L/PGR8clGnEojOSet 299b52E0IjIO5SKG62lAPluxHr5V/ErM3LNtWP1ctsvCqJr51ArC/4cC+UYAxYPmT7U0 tr0SpoSjjAg4jMlFSvyywHs4HTj2hYVF9+ccYFfbddtNZXQGlzU7wdkncOFUvcuMacnf 7iJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=mlANSXqkRIS+uafV6MvTmd7E01TJ70/P1xceNx67Pmo=; b=kEjCQ2uGv6CCw7lJD8LHA7LG3LoNecd6nq/RhMyp5Y5zl0kp5Oi2m0VYzerqcho4Fb NbmV9pmku9Mxtjw+CKnh79cw8rqNY5XOuYUgeThMYT847fmb4nQZZSHIHSNwgd35mG6H 6R0go7N/Jm059jab/tXxZWDlv1Qae1oZQSDrw7fkNxP5jsDWu4K9e0jij7x1pGzuzAk1 kjYlAVckstrfOmn6RWhlV3hC28+jY1B8TVwpFJv6NAhKC15bDQmdt81kAqXtfKkGhHZQ bOqTC3yN16TspiDrhVx9EPbBdy1THZDl0tRT6hHSpAJgxhf4meEz8b6c3dIY6FVOjACu 7NVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=AzJPoGXX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d18-20020a170902ced200b001968c61066esi31890043plg.493.2023.03.30.04.52.48; Thu, 30 Mar 2023 04:53:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=AzJPoGXX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231811AbjC3Lul (ORCPT + 99 others); Thu, 30 Mar 2023 07:50:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231565AbjC3Lu2 (ORCPT ); Thu, 30 Mar 2023 07:50:28 -0400 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ACB3155AF; Thu, 30 Mar 2023 04:50:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1680177026; x=1711713026; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4/nsBozr9Yxm1Svh3lW2TBRBUO1KN1TDzMtK6uriOCA=; b=AzJPoGXX2ZepZVsKvtRD644FyKJ8pUBPSBlhjelq4SlrFY0AupvJIpdK U/qUBk6INCSzYt4LvSobyzVsQ8MFz5M39rODPHFMPyDdTLTI6geQbMbIs GGLZL3w24VzjHCnofqLkFsL1YP0dHuwNCHv0LQwizSrBzNyy1n3sY55Mr UpYVa7ILqOzgUoXRIHmImpkUIKRVDphyvT7GrlvQ3wDrI2CBwq+ZQz/8n NaAkCYCBN97wFv7FXKVdiidqwCmNIvkq9T7K++s41MB9PWOzhRSJ4uWLa VzcDrE603zCiM/DStDeEu7cQTTOsZ2sf/NKIirkWJwhHZ3n5yn12zdmct g==; X-IronPort-AV: E=McAfee;i="6600,9927,10664"; a="342756691" X-IronPort-AV: E=Sophos;i="5.98,303,1673942400"; d="scan'208";a="342756691" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Mar 2023 04:50:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10664"; a="634856368" X-IronPort-AV: E=Sophos;i="5.98,303,1673942400"; d="scan'208";a="634856368" Received: from ngreburx-mobl.ger.corp.intel.com (HELO box.shutemov.name) ([10.251.209.91]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Mar 2023 04:50:02 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id 105B310438F; Thu, 30 Mar 2023 14:50:00 +0300 (+03) From: "Kirill A. Shutemov" To: Borislav Petkov , Andy Lutomirski , Sean Christopherson , Andrew Morton , Joerg Roedel , Ard Biesheuvel Cc: Andi Kleen , Kuppuswamy Sathyanarayanan , David Rientjes , Vlastimil Babka , Tom Lendacky , Thomas Gleixner , Peter Zijlstra , Paolo Bonzini , Ingo Molnar , Dario Faggioli , Dave Hansen , Mike Rapoport , David Hildenbrand , Mel Gorman , marcelo.cerri@canonical.com, tim.gardner@canonical.com, khalid.elmously@canonical.com, philip.cox@canonical.com, aarcange@redhat.com, peterx@redhat.com, x86@kernel.org, linux-mm@kvack.org, linux-coco@lists.linux.dev, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: [PATCHv9 04/14] mm/page_alloc: Add sysfs handle to accept accept_memory Date: Thu, 30 Mar 2023 14:49:46 +0300 Message-Id: <20230330114956.20342-5-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230330114956.20342-1-kirill.shutemov@linux.intel.com> References: <20230330114956.20342-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.4 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Write amount of memory to accept into the new sysfs handle /sys/kernel/mm/page_alloc/accept_memory. Write 'all' to the handle to accept all memory in the system. It can be used to implement background memory accepting from userspace. It is also useful for debugging. Signed-off-by: Kirill A. Shutemov --- mm/page_alloc.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 509a93b7e5af..07e16e9b49c4 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -7343,6 +7343,45 @@ static bool __free_unaccepted(struct page *page) return true; } +static ssize_t accept_memory_store(struct kobject *kobj, + struct kobj_attribute *attr, + const char *buf, size_t count) +{ + unsigned long to_accept = 0; + struct zone *zone; + char *retptr; + + if (sysfs_streq(buf, "all")) { + to_accept = ULONG_MAX; + } else { + to_accept = memparse(buf, &retptr); + + /* Get rid of trailing whitespace, including '\n' */ + retptr = skip_spaces(retptr); + + if (*retptr != 0 || to_accept == 0) + return -EINVAL; + } + + for_each_populated_zone(zone) { + while (try_to_accept_memory_one(zone)) { + if (to_accept <= PAGE_SIZE << MAX_ORDER) + return count; + + to_accept -= PAGE_SIZE << MAX_ORDER; + } + } + + return count; +} + +static struct kobj_attribute accept_memory_attr = __ATTR_WO(accept_memory); + +static struct attribute *page_alloc_attr[] = { + &accept_memory_attr.attr, + NULL +}; + #else static bool page_contains_unaccepted(struct page *page, unsigned int order) @@ -7366,3 +7405,28 @@ static bool __free_unaccepted(struct page *page) } #endif /* CONFIG_UNACCEPTED_MEMORY */ + +static const struct attribute_group page_alloc_attr_group = { +#ifdef CONFIG_UNACCEPTED_MEMORY + .attrs = page_alloc_attr, +#endif +}; + +static int __init page_alloc_init_sysfs(void) +{ + struct kobject *page_alloc_kobj; + int err; + + page_alloc_kobj = kobject_create_and_add("page_alloc", mm_kobj); + if (!page_alloc_kobj) + return -ENOMEM; + + err = sysfs_create_group(page_alloc_kobj, &page_alloc_attr_group); + if (err) { + kobject_put(page_alloc_kobj); + return err; + } + + return 0; +} +late_initcall(page_alloc_init_sysfs); -- 2.39.2