From patchwork Tue Feb 27 02:40:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Barry Song <21cnbao@gmail.com> X-Patchwork-Id: 13573213 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 8A0D1C48BF6 for ; Tue, 27 Feb 2024 02:41:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1C4596B0133; Mon, 26 Feb 2024 21:41:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 174DC6B0134; Mon, 26 Feb 2024 21:41:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 03E366B0136; Mon, 26 Feb 2024 21:41:08 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id E99286B0133 for ; Mon, 26 Feb 2024 21:41:08 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 2405640A7D for ; Tue, 27 Feb 2024 02:41:08 +0000 (UTC) X-FDA: 81836031816.12.B4E9B4C Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) by imf07.hostedemail.com (Postfix) with ESMTP id 564DA40003 for ; Tue, 27 Feb 2024 02:41:05 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=WabFFWfJ; spf=pass (imf07.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.210.169 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709001665; a=rsa-sha256; cv=none; b=sLKS51wxNnFZHmoDKXFahCiqfBvrUoF5LOxkeHfbi5qOgqkBviQTG8DHMmV1fUOwH/OB9b Wcghp7rbp2XYnhdglWHvN6zhkaHTBGEkEgd2uPHTFmG4hoe+FTguzbRJYr0WJfIfWAFUFX bxSgE5tZboyO5XHnwRNiLFlnw+nBWMU= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=WabFFWfJ; spf=pass (imf07.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.210.169 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709001665; 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:references:dkim-signature; bh=+9kPnEQQtmu12UoNhoLVM4of9Nt6V7crsGL0uVHcTJA=; b=jNpJOAlT+kKMwVR6Grwbe12+p5kaGWDyBuNLkWb5zq037AVW6kTaVVd/fZLhlQVOmWYcy9 zMmXEkJ3MrwNUPmUHKLinblJWF4SgbuaDlDqVwWqXbvlthzHRo5i2Wn3boEWwRGDA29zgL 0B33CKiVRDXiprcZo7jOPsQ39zDZiNY= Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-6e508725b64so674182b3a.3 for ; Mon, 26 Feb 2024 18:41:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709001664; x=1709606464; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=+9kPnEQQtmu12UoNhoLVM4of9Nt6V7crsGL0uVHcTJA=; b=WabFFWfJgtdhps4qRC1YVUdZD7NB0GmAooj7bDFZ1LuprdwU/P1QD+vhtC7PlL1lyi XU5+aB03PZ63l/2aMX5Uof1CpNASuNrZS/PqC+eEz5NlBzrOf6KXTTRSSR6upcI44N19 1AoOvi7FWoqYh5+RKkcJmn4X3a/J7YmI6BiMTbO0OnCF519sTFj4o0v5BqH/kLCHtnbu 74j06+dfVXCcapFxqp19XQFm9Y2G+Gz7ut7mVjClnO1fbU64Iu2SvMPp5Sc2M3F3VtVj dS2nRiQZeVndy7q9oxdpynMeVRDD4zt4wEflleVEhxTDuklnXs2Ban76xf0jtONSmIgk 3uIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709001664; x=1709606464; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+9kPnEQQtmu12UoNhoLVM4of9Nt6V7crsGL0uVHcTJA=; b=uAo7qov/VvzIcxJbrzA41pFwPHchf9Xy7LhEA/v0QU/SNt+8GlDxgBpgylSWh5ojHr dv5p96gOw/u1ueKWxilTt0hQIrMLMTcN0YIaosnxCdJiwIdnfQZVP7GYapY4aG7fjUm1 cEUcWUsQ/JX+mPp358QRZ0b0oKopJs3OkZrJYixJrS5VoF4bFdUKu4G5kbiJtUjwwnH4 eaXWGsmKOEcjkjQby0cOEoMUsmTE9l5lS846VjjWMoYKxfANp/EgUDtSMN68QHNjs2q+ Qem5R4h5CZJosTJE561Z6KV8y25Lj6J5Sa1o+T+qcU36PeyUpGJVYgHChdwVdTVl90Q4 diDQ== X-Forwarded-Encrypted: i=1; AJvYcCWwSwza2/xOBcQmC5SpeKOVfJU+ANoitWMG08LooSQzOl6CVfP3jrm1IRAHC5kTy0cTZn4yJhTPFMB+laWkRCp7t88= X-Gm-Message-State: AOJu0YxiRAxay2LrVytzVuEFFscZzzZNGripz80/ZgXrctyikZc9pEWm tHV4SrVgQxF8Aysm4EIkyHA+bUEvp9BLVdnY06ypYgzDj6RoDrpJ X-Google-Smtp-Source: AGHT+IGiB0yNLS+947SzPqW5TZ7PC1hIalQTf7qMGyIVa2Qhsl/G3WdYUU1A+6vXBy5lSjliOsUZ7w== X-Received: by 2002:a17:902:6847:b0:1dc:a834:5e1c with SMTP id f7-20020a170902684700b001dca8345e1cmr3256626pln.11.1709001663911; Mon, 26 Feb 2024 18:41:03 -0800 (PST) Received: from barry-desktop.hub ([2407:7000:8942:5500:fae4:3bff:fecb:410]) by smtp.gmail.com with ESMTPSA id i3-20020a170902c94300b001d706e373a9sm358616pla.292.2024.02.26.18.41.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 18:41:03 -0800 (PST) From: Barry Song <21cnbao@gmail.com> To: akpm@linux-foundation.org, linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, Barry Song , Lance Yang , Ryan Roberts , David Hildenbrand , Yin Fengwei Subject: [PATCH] mm: export folio_pte_batch as a couple of modules might need it Date: Tue, 27 Feb 2024 15:40:50 +1300 Message-Id: <20240227024050.244567-1-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 564DA40003 X-Stat-Signature: yjrqn8m49brfawrs3e3zyja1iithfce4 X-Rspam-User: X-HE-Tag: 1709001665-471661 X-HE-Meta: U2FsdGVkX19KfutsDyQa5q33bx/vqqhGGFJmnUvN6ml1+Z37gKYtcf0FA/XPp2PHliQMsPhlb/X3/D+GuA4tZT/1hO79NwNu2nzY7TVYOz2NIEhWbb1hiCykAnSrUKwjmZCl25Ca8TKfwnJhPxtgWfoett9swpOP2IEnGLBT1HQLg3AyknjzTFuRBPDMhvmTEOlmMlIyCml8dsU+t+W4vWiXJUo1BuipeCOGAltEYi7iXSwbnuI55o5SYATBYpXEzXx6Lr9Ew52MegDjerWU85ksiVuDsF+oG12Jj4mDV04NnWy0DhLPCSPKjfvkqiA1qWHX9YFrPrJJt/YO6qA9ECYDJkKD1FTDQ2giKRd4f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wFIZdOU5GVXlJaIrjzc068H6CmybhHSaDk9CkaRX2QHrwy3X7KWwTJ20RAp6+W/+RBA7K/5g7UXtQzvR0MZbaQ3UfG9BekqsnfuY3g2vn5H8H/cbtssfM8FkZcsGiDDBR/c7EGQFwbTk/6N3xQteGnn58JXu4lquBp3SoYZcc2FA3+lQGmedQugiThDiDP/t9IIxseQtD4mHO8P6s4eQkn8sXUw3cV7dzyW/v7VXXnM8Io2PoQyRN9Sr3nTEJK9A== 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: List-Subscribe: List-Unsubscribe: From: Barry Song madvise and some others might need folio_pte_batch to check if a range of PTEs are completely mapped to a large folio with contiguous physcial addresses. Let's export it for others to use. Cc: Lance Yang Cc: Ryan Roberts Cc: David Hildenbrand Cc: Yin Fengwei Signed-off-by: Barry Song Signed-off-by: David Hildenbrand --- -v1: at least two jobs madv_free and madv_pageout depend on it. To avoid conflicts and dependencies, after discussing with Lance, we prefer this one can land earlier. mm/internal.h | 13 +++++++++++++ mm/memory.c | 11 +---------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/mm/internal.h b/mm/internal.h index 13b59d384845..8e2bc304f671 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -83,6 +83,19 @@ static inline void *folio_raw_mapping(struct folio *folio) return (void *)(mapping & ~PAGE_MAPPING_FLAGS); } +/* Flags for folio_pte_batch(). */ +typedef int __bitwise fpb_t; + +/* Compare PTEs after pte_mkclean(), ignoring the dirty bit. */ +#define FPB_IGNORE_DIRTY ((__force fpb_t)BIT(0)) + +/* Compare PTEs after pte_clear_soft_dirty(), ignoring the soft-dirty bit. */ +#define FPB_IGNORE_SOFT_DIRTY ((__force fpb_t)BIT(1)) + +extern int folio_pte_batch(struct folio *folio, unsigned long addr, + pte_t *start_ptep, pte_t pte, int max_nr, fpb_t flags, + bool *any_writable); + void __acct_reclaim_writeback(pg_data_t *pgdat, struct folio *folio, int nr_throttled); static inline void acct_reclaim_writeback(struct folio *folio) diff --git a/mm/memory.c b/mm/memory.c index 1c45b6a42a1b..319b3be05e75 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -953,15 +953,6 @@ static __always_inline void __copy_present_ptes(struct vm_area_struct *dst_vma, set_ptes(dst_vma->vm_mm, addr, dst_pte, pte, nr); } -/* Flags for folio_pte_batch(). */ -typedef int __bitwise fpb_t; - -/* Compare PTEs after pte_mkclean(), ignoring the dirty bit. */ -#define FPB_IGNORE_DIRTY ((__force fpb_t)BIT(0)) - -/* Compare PTEs after pte_clear_soft_dirty(), ignoring the soft-dirty bit. */ -#define FPB_IGNORE_SOFT_DIRTY ((__force fpb_t)BIT(1)) - static inline pte_t __pte_batch_clear_ignored(pte_t pte, fpb_t flags) { if (flags & FPB_IGNORE_DIRTY) @@ -982,7 +973,7 @@ static inline pte_t __pte_batch_clear_ignored(pte_t pte, fpb_t flags) * If "any_writable" is set, it will indicate if any other PTE besides the * first (given) PTE is writable. */ -static inline int folio_pte_batch(struct folio *folio, unsigned long addr, +int folio_pte_batch(struct folio *folio, unsigned long addr, pte_t *start_ptep, pte_t pte, int max_nr, fpb_t flags, bool *any_writable) {