From patchwork Thu Jun 16 17:48:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12884646 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 D0517C433EF for ; Thu, 16 Jun 2022 17:48:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CF5B36B007B; Thu, 16 Jun 2022 13:48:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CA3BF6B007E; Thu, 16 Jun 2022 13:48:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AF59D6B0080; Thu, 16 Jun 2022 13:48:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id A08246B007B for ; Thu, 16 Jun 2022 13:48:58 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 78FCC215BC for ; Thu, 16 Jun 2022 17:48:58 +0000 (UTC) X-FDA: 79584834756.22.1896764 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by imf18.hostedemail.com (Postfix) with ESMTP id 1E29B1C007C for ; Thu, 16 Jun 2022 17:48:57 +0000 (UTC) Received: by mail-pf1-f170.google.com with SMTP id y6so2093121pfr.13 for ; Thu, 16 Jun 2022 10:48:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QRTCWUz/v80cwRev6O447pCBMSdMFGV94XhB5oNBreQ=; b=Fm5abIw414WczmkiARiuOIB9/0ASIunFH2zFKcRTz+KBNKvcBYcmyc+rwz37WtNCMN Q91YdwCifI/utdZj36nMuMzQ4+xEtVBzz4U+2d8nLuOBijN4D6KkGIrGsfWfJqgzx88i N4serWC67hGg9tGb1K1E+W3IM/ktOQLXj8AjMMv2xSPVvxkLY8yTbIBB23hujhfKIjuF qR8R2Fl5Vg/GOWk7BTeueqJwqM3OPvf3ZTwxKrBpWmtBKIO+6AXuItMuxGrDC5dm3FVJ yOYhpdT39E1dzHRcviaiO05a4p0BqyMWfcINITHFuS6WnG9CxsdiuWgtrO7U4uWx+vZy 185Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QRTCWUz/v80cwRev6O447pCBMSdMFGV94XhB5oNBreQ=; b=YdDgYsOsLp+VrbTR1Xlj6sr6tnK30l/C3fOrEvl2nQOb2Ech156JgJgRWMLAFdq8un m0Tt/BVvol8HqA37AlBV0ZFHskunwa+Mu6tonBwVrF3bT0bfRbpzaZ37dqh+C0slFP8V qbb5abUROLlO3JBoeV11haKRh7doH5Wib5dEyvM2bQnvaL7grU4Vn9K/Ubz8lbJSlvFU AVPY2HQwW7NFq1rH3UiW3Ob6O0PkBkWQNuLGNkHHKi64mUxDd+XG5mboEFNIiZgCiFEi SyY6PBjJ3UZ04U32MbAiUCCKiBjpbDDMxoIg6ts2kKqXJwSFoaeglth8k1fGEPtZXcQN QXIg== X-Gm-Message-State: AJIora+S1UcmmhFE2W+pmUgfVVQs7oXtHFAfISXcZKX0deAt7uWwj2qp 0lHpDyyiv+rbs3gczj0OQMM= X-Google-Smtp-Source: AGRyM1vnH5OfaqcNXG9WeXIL0jSqmq4SmAlVZPgdAgD+zxW+JwxF7guIJVE0p/eybVg5QN/5LR3qRg== X-Received: by 2002:a05:6a00:1513:b0:51c:3ca8:47a4 with SMTP id q19-20020a056a00151300b0051c3ca847a4mr5967135pfu.48.1655401737201; Thu, 16 Jun 2022 10:48:57 -0700 (PDT) Received: from localhost.localdomain (c-67-174-241-145.hsd1.ca.comcast.net. [67.174.241.145]) by smtp.gmail.com with ESMTPSA id z21-20020a17090a8b9500b001e8520b211bsm1818289pjn.53.2022.06.16.10.48.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jun 2022 10:48:56 -0700 (PDT) From: Yang Shi To: vbabka@suse.cz, kirill.shutemov@linux.intel.com, willy@infradead.org, zokeefe@google.com, linmiaohe@huawei.com, akpm@linux-foundation.org Cc: shy828301@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [v5 PATCH 6/7] mm: khugepaged: reorg some khugepaged helpers Date: Thu, 16 Jun 2022 10:48:39 -0700 Message-Id: <20220616174840.1202070-7-shy828301@gmail.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20220616174840.1202070-1-shy828301@gmail.com> References: <20220616174840.1202070-1-shy828301@gmail.com> MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Fm5abIw4; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf18.hostedemail.com: domain of shy828301@gmail.com designates 209.85.210.170 as permitted sender) smtp.mailfrom=shy828301@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655401738; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=QRTCWUz/v80cwRev6O447pCBMSdMFGV94XhB5oNBreQ=; b=5smDDNXWchLWj+6HihyU6uUOnEod/hrOxogDBk09N6HOhHFYXc5lOT8DOfjhuLUdVTN3uX I614mvZral8lK5gv7aolqhP5twGV/chxdvESj8M4yp5FqsVN/xWvBOcaU+EYPw6ezcXZxX WzYy71Kctj74VNVdw5jflv+oaNrMSGw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655401738; a=rsa-sha256; cv=none; b=iChhZrh4884W7rrSJEGnDwrLQ584HaPAbXFOwCVN0qjk1M3Y2kTV054jZJVx34hfDOosdN qT9huREmYjwESECXHbEvbxyKrYsJJNEJCivdpkovRjWournpYc0lZn13EL0QB2+Fjb5jD7 rueoL3F4MAlaas1603p4COcC/uR1aFM= X-Stat-Signature: 64dr6kdii846uyfwp54kyi9xfe4knucz X-Rspamd-Queue-Id: 1E29B1C007C X-Rspam-User: Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Fm5abIw4; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf18.hostedemail.com: domain of shy828301@gmail.com designates 209.85.210.170 as permitted sender) smtp.mailfrom=shy828301@gmail.com X-Rspamd-Server: rspam10 X-HE-Tag: 1655401737-85421 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: The khugepaged_{enabled|always|req_madv} are not khugepaged only anymore, move them to huge_mm.h and rename to hugepage_flags_xxx, and remove khugepaged_req_madv due to no users. Also move khugepaged_defrag to khugepaged.c since its only caller is in that file, it doesn't have to be in a header file. Reviewed-by: Zach O'Keefe Signed-off-by: Yang Shi --- include/linux/huge_mm.h | 8 ++++++++ include/linux/khugepaged.h | 14 -------------- mm/huge_memory.c | 4 ++-- mm/khugepaged.c | 18 +++++++++++------- 4 files changed, 21 insertions(+), 23 deletions(-) diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index cd8a6c5d9fe5..ae3d8e2fd9e2 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -116,6 +116,14 @@ extern struct kobj_attribute shmem_enabled_attr; extern unsigned long transparent_hugepage_flags; +#define hugepage_flags_enabled() \ + (transparent_hugepage_flags & \ + ((1<flags)) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index d0c37d99917b..0f2cce2d7041 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -117,11 +117,11 @@ bool hugepage_vma_check(struct vm_area_struct *vma, if (!in_pf && shmem_file(vma->vm_file)) return shmem_huge_enabled(vma); - if (!khugepaged_enabled()) + if (!hugepage_flags_enabled()) return false; /* THP settings require madvise. */ - if (!(vm_flags & VM_HUGEPAGE) && !khugepaged_always()) + if (!(vm_flags & VM_HUGEPAGE) && !hugepage_flags_always()) return false; /* Only regular file is valid */ diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 2a676f37c921..d8ebb60aae36 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -472,7 +472,7 @@ void khugepaged_enter_vma(struct vm_area_struct *vma, unsigned long vm_flags) { if (!test_bit(MMF_VM_HUGEPAGE, &vma->vm_mm->flags) && - khugepaged_enabled()) { + hugepage_flags_enabled()) { if (hugepage_vma_check(vma, vm_flags, false, false)) __khugepaged_enter(vma->vm_mm); } @@ -763,6 +763,10 @@ static bool khugepaged_scan_abort(int nid) return false; } +#define khugepaged_defrag() \ + (transparent_hugepage_flags & \ + (1<