From patchwork Sat Jun 4 00:39:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zach O'Keefe X-Patchwork-Id: 12869462 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D05AC433EF for ; Sat, 4 Jun 2022 00:40:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4FDB88D0008; Fri, 3 Jun 2022 20:40:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4AC578D0001; Fri, 3 Jun 2022 20:40:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3C5468D0008; Fri, 3 Jun 2022 20:40:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 0E8BC8D0001 for ; Fri, 3 Jun 2022 20:40:22 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id D77DD1210F9 for ; Sat, 4 Jun 2022 00:40:21 +0000 (UTC) X-FDA: 79538697084.16.96DF4E5 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) by imf31.hostedemail.com (Postfix) with ESMTP id 422162002E for ; Sat, 4 Jun 2022 00:39:38 +0000 (UTC) Received: by mail-pf1-f202.google.com with SMTP id z5-20020aa79f85000000b0051baa4e9fb8so4690852pfr.7 for ; Fri, 03 Jun 2022 17:40:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=boI9sUc1aLaPy+/Moqq/dXZm751GICf2cmQgqbxclaA=; b=rCI1h7hlaF0PygOkLN8m2eeS5QJqEqC0yYCr3IIBCKgZW11wIBMvWjaI044IxdQqKp 8p8hzNgjJC55489ei4y7+hF4qXlhp6IZJf8lUDhQrUigZ839PQyYl9Xl3PyiSuLdtQaN f+t6E59dnuWoALDgyRAAyRFOXAtV4IdpbFgS5l4GXs154GIQJgBjriXSbFiVTdPVwciR cyiaRciXLWfe4nnYleHkXNfTGoNcTyTBv3uWjngNylCwxPEY1Pv5PrK6Eazf6awxRjm6 S2fCbyex8C7/Onxdp3+erocoTyMg79SXAsSsKDfOS6OQVkE4YvWXFtPToAP0jC8/q1Om qyqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=boI9sUc1aLaPy+/Moqq/dXZm751GICf2cmQgqbxclaA=; b=iRFrLLYpzvIIMeB/ALActBCRciM92+/k4p6fD0gKpSTRyR949BLP8305VVwMg6SoZE fq2oSmOiMToxTMuYGH2ICye5TNj9Ncu/AuZxTAnTMXORMjrgz7SLOHeZf8TspVzFMHkk 7VpTqWvfSDuuFfqZUlDgzjtxfqhPwl0UGP3hwwjqIZ8aB9MWPODpPftQQQMtdF/58B6I OQwoSO1Y6A5yYF5G3T2AINmKcIpE0y2w/wstJnyQj21N53OvnsIJe+WxTZTdw9T3Tsew 9prKBMmTPEipKnA/ugYNgFq2Agk3FjLeizocnPbqr0vi1SJ6d8n0OhU9/zbb2Me7D0TA LJdQ== X-Gm-Message-State: AOAM530MsPxYLGcpsQ6TFs94tf3NUwBDrdI/gnv+Bs4rVNfwnq9IHBJo jAx0HHlHxcg7HR6QquCuHhnncSfhsiyV X-Google-Smtp-Source: ABdhPJzsfLCGH4ERn3EghZbHMFsR+OktFe2zv4niVZS3+A5tNo0JsMGLtHC/yoQQdITL227iFZT/UH5iylXT X-Received: from zokeefe3.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1b6]) (user=zokeefe job=sendgmr) by 2002:a17:902:ea53:b0:15b:1bb8:ac9e with SMTP id r19-20020a170902ea5300b0015b1bb8ac9emr12175559plg.45.1654303220573; Fri, 03 Jun 2022 17:40:20 -0700 (PDT) Date: Fri, 3 Jun 2022 17:39:54 -0700 In-Reply-To: <20220604004004.954674-1-zokeefe@google.com> Message-Id: <20220604004004.954674-6-zokeefe@google.com> Mime-Version: 1.0 References: <20220604004004.954674-1-zokeefe@google.com> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH v6 05/15] mm/khugepaged: make allocation semantics context-specific From: "Zach O'Keefe" To: Alex Shi , David Hildenbrand , David Rientjes , Matthew Wilcox , Michal Hocko , Pasha Tatashin , Peter Xu , Rongwei Wang , SeongJae Park , Song Liu , Vlastimil Babka , Yang Shi , Zi Yan , linux-mm@kvack.org Cc: Andrea Arcangeli , Andrew Morton , Arnd Bergmann , Axel Rasmussen , Chris Kennelly , Chris Zankel , Helge Deller , Hugh Dickins , Ivan Kokshaysky , "James E.J. Bottomley" , Jens Axboe , "Kirill A. Shutemov" , Matt Turner , Max Filippov , Miaohe Lin , Minchan Kim , Patrick Xia , Pavel Begunkov , Thomas Bogendoerfer , "Zach O'Keefe" X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 422162002E X-Stat-Signature: p5aijajgzsk95wqpg8cy3tbkhnf1mdi7 Authentication-Results: imf31.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=rCI1h7hl; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf31.hostedemail.com: domain of 39KmaYgcKCM0I73xxyxz77z4x.v75416DG-553Etv3.7Az@flex--zokeefe.bounces.google.com designates 209.85.210.202 as permitted sender) smtp.mailfrom=39KmaYgcKCM0I73xxyxz77z4x.v75416DG-553Etv3.7Az@flex--zokeefe.bounces.google.com X-HE-Tag: 1654303178-55613 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add a gfp_t flags member to struct collapse_control that allows contexts to specify their own allocation semantics. This decouples the allocation semantics from /sys/kernel/mm/transparent_hugepage/khugepaged/defrag. khugepaged updates this member for every hugepage processed, since the sysfs setting might change at any time. Signed-off-by: Zach O'Keefe --- mm/khugepaged.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 38488d114073..ba722347bebd 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -92,6 +92,9 @@ struct collapse_control { /* Last target selected in khugepaged_find_target_node() */ int last_target_node; + + /* gfp used for allocation and memcg charging */ + gfp_t gfp; }; /** @@ -994,15 +997,14 @@ static bool __collapse_huge_page_swapin(struct mm_struct *mm, return true; } -static int alloc_charge_hpage(struct page **hpage, struct mm_struct *mm, +static int alloc_charge_hpage(struct mm_struct *mm, struct page **hpage, struct collapse_control *cc) { - gfp_t gfp = alloc_hugepage_khugepaged_gfpmask() | __GFP_THISNODE; int node = khugepaged_find_target_node(cc); - if (!khugepaged_alloc_page(hpage, gfp, node)) + if (!khugepaged_alloc_page(hpage, cc->gfp, node)) return SCAN_ALLOC_HUGE_PAGE_FAIL; - if (unlikely(mem_cgroup_charge(page_folio(*hpage), mm, gfp))) + if (unlikely(mem_cgroup_charge(page_folio(*hpage), mm, cc->gfp))) return SCAN_CGROUP_CHARGE_FAIL; count_memcg_page_event(*hpage, THP_COLLAPSE_ALLOC); return SCAN_SUCCEED; @@ -1032,7 +1034,7 @@ static void collapse_huge_page(struct mm_struct *mm, unsigned long address, */ mmap_read_unlock(mm); - result = alloc_charge_hpage(hpage, mm, cc); + result = alloc_charge_hpage(mm, hpage, cc); if (result != SCAN_SUCCEED) goto out_nolock; @@ -1613,7 +1615,7 @@ static void collapse_file(struct mm_struct *mm, struct file *file, VM_BUG_ON(!IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) && !is_shmem); VM_BUG_ON(start & (HPAGE_PMD_NR - 1)); - result = alloc_charge_hpage(hpage, mm, cc); + result = alloc_charge_hpage(mm, hpage, cc); if (result != SCAN_SUCCEED) goto out; @@ -2037,8 +2039,7 @@ static void khugepaged_scan_file(struct mm_struct *mm, struct file *file, } #else static void khugepaged_scan_file(struct mm_struct *mm, struct file *file, - pgoff_t start, struct page **hpage, - struct collapse_control *cc) + pgoff_t start, struct collapse_control *cc) { BUILD_BUG(); } @@ -2121,6 +2122,9 @@ static unsigned int khugepaged_scan_mm_slot(unsigned int pages, if (unlikely(khugepaged_test_exit(mm))) goto breakouterloop; + /* reset gfp flags since sysfs settings might change */ + cc->gfp = alloc_hugepage_khugepaged_gfpmask() | + __GFP_THISNODE; VM_BUG_ON(khugepaged_scan.address < hstart || khugepaged_scan.address + HPAGE_PMD_SIZE > hend); @@ -2255,6 +2259,7 @@ static int khugepaged(void *none) struct mm_slot *mm_slot; struct collapse_control cc = { .last_target_node = NUMA_NO_NODE, + /* .gfp set later */ }; set_freezable();