From patchwork Tue Jan 7 03:04:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13928024 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 5C06BE77188 for ; Tue, 7 Jan 2025 03:04:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 93B386B0083; Mon, 6 Jan 2025 22:04:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8C3CE6B0089; Mon, 6 Jan 2025 22:04:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 764F06B008C; Mon, 6 Jan 2025 22:04:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 5802A6B0083 for ; Mon, 6 Jan 2025 22:04:23 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id D219F120556 for ; Tue, 7 Jan 2025 03:04:22 +0000 (UTC) X-FDA: 82979162364.04.46CB724 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) by imf15.hostedemail.com (Postfix) with ESMTP id 218B1A0009 for ; Tue, 7 Jan 2025 03:04:20 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=KOWzSk8F; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf15.hostedemail.com: domain of 3s5l8ZwYKCBwKMJ6F38GG8D6.4GEDAFMP-EECN24C.GJ8@flex--surenb.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=3s5l8ZwYKCBwKMJ6F38GG8D6.4GEDAFMP-EECN24C.GJ8@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736219061; 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-type:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=IAKugViAv2vyxsDo1uwcQZx4rpptnMiInyJAyrim7q0=; b=O+4ePz05gLrGlSYOOUI9dcX7cf5XkP3uD0O6A/h7UOCOBam5NvMd2EYabiU9Gv5dsuspqP h9VLTrL/2/FkvtaS+rBaPIddYPljBPTIyAWEyHv/AsW8mUUV0dlCwnRkma7rSxUjYzM+rK CpUuuQ7uWklqGKiFAscQan03wg/T8Yc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736219061; a=rsa-sha256; cv=none; b=t1zs+YlAIVzzTwtdo4nCtLuJb3kaei0foVGSZlHAAjvZH5Wns42JM+k6dhJ7g7ZEAuKeXz Wd/h0I8mDNUEajtvBaL4v8l9jbwl6hPZdmH8bMcHjhuzmDD+K5Z4cjAXxTwo6WJZZHiIp6 dfsEvFNyH2ALFPFph2PUXn86+E/YijY= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=KOWzSk8F; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf15.hostedemail.com: domain of 3s5l8ZwYKCBwKMJ6F38GG8D6.4GEDAFMP-EECN24C.GJ8@flex--surenb.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=3s5l8ZwYKCBwKMJ6F38GG8D6.4GEDAFMP-EECN24C.GJ8@flex--surenb.bounces.google.com Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-21a7cbe3b56so1486355ad.0 for ; Mon, 06 Jan 2025 19:04:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736219060; x=1736823860; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=IAKugViAv2vyxsDo1uwcQZx4rpptnMiInyJAyrim7q0=; b=KOWzSk8FTMoqxxXx4ZnSOcBVLi0LhrmXFmxeWjOEDyv1wkEOBJ8l4scYMdALiCcgBJ ELRxzOyE+ocMTstmp6s0UMXs7Cmg2T+NgVFuPSpYAV8XayO4fj7rUn3huzaY9mwj8oRJ nsf8tG/3R1tWhuWEKqqGVDCy9b0eyvKvG7BFE0vP1i/n3ph/cGlye0aCaKE2OO92Er7g HIj4SbTusq6fqDdMDD3SuBr24ZqyYTQUKMGTDWAdO8AkyCI3q5t0pxoVOXOoMYVfbZBn fAXDl/GvDWnfedKOEDwIg0DjW6Pea3IQ0PXEkA4ZkWf5+TehfMKck9uMPgvO/+HWz6o6 gqOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736219060; x=1736823860; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=IAKugViAv2vyxsDo1uwcQZx4rpptnMiInyJAyrim7q0=; b=jpnVp7gmrvlf3WUJtZNBKGsjaWhNPaRvOOg0KDDQMKvrdvWpENrCJhqad8uGCSI2T9 AzvVYJmRsOuyjgZGNHn47JbC3Oz/iFIfy/4kDlLeypOam7h/dg6zWSKyDBl382Nv+ykp yHZ7kLAIjNaKltbLQq95HznSYU2zuofvBVbCFIhL8UNG/7rzVs26AujibxRFkVRWfoBu 7Ljwl07jz6tyw2miqzSHY/XUI9akyslysP3aw0L5blevzczV0fG2EIM8IFi5C1iz+CpD D0CRWwyMaJ7oDfGVeAEvRI9J07BII60YBt2DZYKlYJEOYoMfoR9Dr2gKWOWBiG+M/Pu+ kIug== X-Forwarded-Encrypted: i=1; AJvYcCWWppY1A0llphKZ5hwfV08i1WHd4twYC9dqhKviegh0K4l+UtqRn9RPRhomAa/hFBYoFqdSogwBUA==@kvack.org X-Gm-Message-State: AOJu0YzY5oLHayhB07JZ8HQBLnqOTLleDiHqdAc6p8Pmmft7oLspY6Xn vULY3HPCWgm3t0JE8piKQqfwvrwScqkGYlobHabIGitwEudbvQOAs+r6gvlujzluX04ildz/b+j 7iA== X-Google-Smtp-Source: AGHT+IEg95xZ0xDmICag3aY02ywplEVuehknTygKn8G6rDFUwwaEkm+rFMld7kyFOrds6elBt2izNVcIS9o= X-Received: from pfms15.prod.google.com ([2002:aa7:828f:0:b0:72a:bcc3:4c9a]) (user=surenb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:78aa:b0:1e1:ae82:5657 with SMTP id adf61e73a8af0-1e5e080282fmr90631848637.34.1736219059615; Mon, 06 Jan 2025 19:04:19 -0800 (PST) Date: Mon, 6 Jan 2025 19:04:15 -0800 Mime-Version: 1.0 X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20250107030415.721474-1-surenb@google.com> Subject: [PATCH 1/1] mm: remove extra check for VMA_LOCK_OFFSET when read-locking a vma From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: richard.weiyang@gmail.com, peterz@infradead.org, willy@infradead.org, liam.howlett@oracle.com, lorenzo.stoakes@oracle.com, mhocko@suse.com, vbabka@suse.cz, hannes@cmpxchg.org, mjguzik@gmail.com, oliver.sang@intel.com, mgorman@techsingularity.net, david@redhat.com, peterx@redhat.com, oleg@redhat.com, dave@stgolabs.net, paulmck@kernel.org, brauner@kernel.org, dhowells@redhat.com, hdanton@sina.com, hughd@google.com, lokeshgidra@google.com, minchan@google.com, jannh@google.com, shakeel.butt@linux.dev, souravpanda@google.com, pasha.tatashin@soleen.com, klarasmodin@gmail.com, corbet@lwn.net, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@android.com, surenb@google.com X-Stat-Signature: g1hfjw7ogrrbssehwfhjqnofwwfw8dft X-Rspamd-Queue-Id: 218B1A0009 X-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ZPBkEGrs5WaFSOupMl4WyUwEAA9NA0P/ys/cU8Q5SFJo1/RJ+MMwFUOeeQZ6GoDxk8iSIXnvAsmbK8W04f90uWldAcHxaYtrIIay8NS7EHCjGzkpniTfCA0Y6Lq4uDO4FUlsDRe5iTznHRyRZuid+F0wPw06wDGcYYB/QzfC95gUqigIfWbIbJ5I/6RIDnwDtu0lNZ+8d3cnzGzjHOkKNecSBBRiSBtlfu/VwrvbTRw9utypivsH5SQ/N8NdbJdinDXbmNwjrLUqCmwRtfq4NPfzZb16DlQgVO7WyhLdJAsKijLLmStonZNl7yVx2/tYzYw90+V//abQ3pRnfHv0fPKD/4bk1N9Y4gnjnxuI/DACNicecpxJMaLMj3flaJ2dnj1OamrTn24mieWGembrHHXhv7LLnrPFT1wQ7I1A57V0RO2orE5YgPigw4kHaAQHMlUtn7lDhGVRBYUghZOOkNfyyM6oC9CW/yPKRRaZVm9BUUzGZpDJAyTpCdaazHG+pkkGl9SFn+t0Y8Fv0q3eHh9W7vKpPT+sOg8C+WnO6Z84Vq4vVJPDCxhBVTl8g+u6xtV27OFmoaJg4YloNXI7h9xUnDPZnqt2U9PC0NhyXcLsNPP9jiY78UEDnENnuEUvKfAvjRrF92dg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000072, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Since we limit vm_refcnt at VMA_REF_LIMIT and it's smaller than VMA_LOCK_OFFSET, there is no need to check again if VMA_LOCK_OFFSET bit is set. Remove the extra check and add a clarifying comment. Fixes: e8f32ff00a66 ("mm: replace vm_lock and detached flag with a reference count") Suggested-by: Wei Yang Signed-off-by: Suren Baghdasaryan Reviewed-by: Wei Yang --- Applies over mm-unstable include/linux/mm.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) base-commit: f349e79bfbf3abfade8011797ff6d0d47b67dab7 diff --git a/include/linux/mm.h b/include/linux/mm.h index 486638d22fc6..b5f262fc7dc5 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -747,7 +747,11 @@ static inline bool vma_start_read(struct mm_struct *mm, struct vm_area_struct *v rwsem_acquire_read(&vma->vmlock_dep_map, 0, 0, _RET_IP_); - /* Limit at VMA_REF_LIMIT to leave one count for a writer */ + /* + * Limit at VMA_REF_LIMIT to leave one count for a writer. + * If VMA_LOCK_OFFSET is set, __refcount_inc_not_zero_limited() will fail + * because VMA_REF_LIMIT is less than VMA_LOCK_OFFSET. + */ if (unlikely(!__refcount_inc_not_zero_limited(&vma->vm_refcnt, &oldcnt, VMA_REF_LIMIT))) { rwsem_release(&vma->vmlock_dep_map, _RET_IP_); @@ -766,8 +770,7 @@ static inline bool vma_start_read(struct mm_struct *mm, struct vm_area_struct *v * after it has been unlocked. * This pairs with RELEASE semantics in vma_end_write_all(). */ - if (unlikely(oldcnt & VMA_LOCK_OFFSET || - vma->vm_lock_seq == raw_read_seqcount(&mm->mm_lock_seq))) { + if (unlikely(vma->vm_lock_seq == raw_read_seqcount(&mm->mm_lock_seq))) { vma_refcount_put(vma); return false; }