From mboxrd@z Thu Jan 1 00:00:00 1970 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 644ACC52D11 for ; Thu, 26 Jan 2023 17:29:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0486D6B0072; Thu, 26 Jan 2023 12:29:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F1D6A8E0002; Thu, 26 Jan 2023 12:29:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DDAD08E0001; Thu, 26 Jan 2023 12:29:13 -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 CA61A6B0072 for ; Thu, 26 Jan 2023 12:29:13 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id A0DC2AB44B for ; Thu, 26 Jan 2023 17:29:13 +0000 (UTC) X-FDA: 80397636186.27.C5EEC68 Received: from mail-yw1-f179.google.com (mail-yw1-f179.google.com [209.85.128.179]) by imf17.hostedemail.com (Postfix) with ESMTP id 01E5D40014 for ; Thu, 26 Jan 2023 17:29:11 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=ilIqDRwk; spf=pass (imf17.hostedemail.com: domain of surenb@google.com designates 209.85.128.179 as permitted sender) smtp.mailfrom=surenb@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674754152; 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:in-reply-to:references:references:dkim-signature; bh=2gmbLn2mGKjT9Gs0HRiDRhCerJgSSV5gpVvcCzntQ7Y=; b=eVXA3JAcscnv/YbdK5IGniuSPHQP1UKD9H8OSF1SRWShwDhhJQVxL4/Gn4X+dQzNTLeMlr tYc7Y8XzO/0X23TMxi9/cWyX6G+KNFMpZ85rPP7G/+UsO0fVyx83OYWsm8Ndyw3EI3/Nn0 CEIuGT/bGGHiJmwlUIosPOKEfRfoukM= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=ilIqDRwk; spf=pass (imf17.hostedemail.com: domain of surenb@google.com designates 209.85.128.179 as permitted sender) smtp.mailfrom=surenb@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674754152; a=rsa-sha256; cv=none; b=libRNHgUPdSchh129Cl+LMmf8wx7jjud+dNsP7gxZKQ1VyLzHhTL6PzYnRfqvg9XSEh8UQ EcOEXEfu9iUWbHy0EqiMAWaXlhnNP+NAjomNEsalmD9JjC/8E0FqUd9Wzf2bjMduRbh5bx B1DJR+iAkZS0/nP9g97YzRiJgv8XcfM= Received: by mail-yw1-f179.google.com with SMTP id 00721157ae682-506609635cbso32874137b3.4 for ; Thu, 26 Jan 2023 09:29:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=2gmbLn2mGKjT9Gs0HRiDRhCerJgSSV5gpVvcCzntQ7Y=; b=ilIqDRwk14c77kuNcIb1Za5yA/k9MlZMjOIAG7xgew/iubgJyrG32CmDPzNNMjKVU1 0cjAh7/cDiMlBWp7hNnSIwd1PXFNxdlppAGUU7j/d06/fdITUN8na+bPZl4T4FsheJPZ LWsxwR1YcK+FWW2DBQwr6IyKjvLWxbTIMc17+Fd+yndb2sMV2vZnytDbpPDmoBXRB4F7 rleLMvYF/2o2GY6lzSau23qOOMOaf7bdkBeK/sWqCfupZvXUJjT0ZY7RKqeTong9fCDN p4I/CcH8n+tGdongz6ryxejse0aGlrrtzoVh6FNqLByFg1N9TkDnjINbfSncpK90ozHN RLPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=2gmbLn2mGKjT9Gs0HRiDRhCerJgSSV5gpVvcCzntQ7Y=; b=XH2eDkiVQEyqPukle6K+z836PFajw6tZ3lAPDwkkHvVkDC3HNoB5n57ftUvGgLJO5U KGGfyA3PcHJbG4ZEDHjdlfOH+19aT3o/EChZFuESW6FfAgUTRsM4mGQtrOuAj4XfV1cO lTov5hffC/BbjHnrnf2kIyBzX7t3UvULA2nDEUNTtvXA0EqP2bOD5K6F4kmJ56R7gYB5 XSjCJtjQcDbT8ZNTzU7r8gWkHjOOVI0DhK3LPSGDZzJcJpK872Wi1kUpBuVOTunN3tHj B+9LjhJzI4MM5pFTCl0VXOeVH8zi58m2SwC0t7owm6GtE+fN3ht200So5XJp1kEsb8or E4ug== X-Gm-Message-State: AFqh2kpECOZdiqR4+92e5d3ODX96VixIJMRbWRhrgqAISqARbMNGZ+wP SOgWz2QS8uyWvQWnZkqnpKhv4BOFVkZabngV/Fp01Q== X-Google-Smtp-Source: AMrXdXs8M6k6K1NpNfukVCVayvEghbuYahYf046uox5fJ76us0EUsA9otKxgNw134ACA+9mbXdAwd6mqx9pXaEYbxgI= X-Received: by 2002:a81:1d2:0:b0:433:f1c0:3f1c with SMTP id 201-20020a8101d2000000b00433f1c03f1cmr5000022ywb.438.1674754150775; Thu, 26 Jan 2023 09:29:10 -0800 (PST) MIME-Version: 1.0 References: <20230125233554.153109-1-surenb@google.com> <20230125233554.153109-5-surenb@google.com> <20230126151015.ru2m26jkhwib6x6u@techsingularity.net> <20230126172657.bmga5hy74ifsbhun@techsingularity.net> In-Reply-To: <20230126172657.bmga5hy74ifsbhun@techsingularity.net> From: Suren Baghdasaryan Date: Thu, 26 Jan 2023 09:28:59 -0800 Message-ID: Subject: Re: [PATCH v3 4/7] mm: replace vma->vm_flags direct modifications with modifier calls To: Mel Gorman Cc: akpm@linux-foundation.org, michel@lespinasse.org, jglisse@google.com, mhocko@suse.com, vbabka@suse.cz, hannes@cmpxchg.org, dave@stgolabs.net, willy@infradead.org, liam.howlett@oracle.com, peterz@infradead.org, ldufour@linux.ibm.com, paulmck@kernel.org, mingo@redhat.com, will@kernel.org, luto@kernel.org, songliubraving@fb.com, peterx@redhat.com, david@redhat.com, dhowells@redhat.com, hughd@google.com, bigeasy@linutronix.de, kent.overstreet@linux.dev, punit.agrawal@bytedance.com, lstoakes@gmail.com, peterjung1337@gmail.com, rientjes@google.com, axelrasmussen@google.com, joelaf@google.com, minchan@google.com, jannh@google.com, shakeelb@google.com, tatashin@google.com, edumazet@google.com, gthelen@google.com, gurua@google.com, arjunroy@google.com, soheil@google.com, hughlynch@google.com, leewalsh@google.com, posk@google.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, x86@kernel.org, linux-kernel@vger.kernel.org, kernel-team@android.com Content-Type: text/plain; charset="UTF-8" X-Stat-Signature: rzqcc8dexkfufshgnw4j1g1fjnn1s9x1 X-Rspam-User: X-Rspamd-Queue-Id: 01E5D40014 X-Rspamd-Server: rspam06 X-HE-Tag: 1674754151-870044 X-HE-Meta: U2FsdGVkX1/7FT5E7oxRgQi2AWCaT6VrGRJAEioJa/qSLOJVbG4O0mLXyRlLiTSktG3lL/wctMCrt7XWP2+a9QTOjNc07g9KQAOUH94aOVjnuQArnFOzy7lniUYVFrZ3EZQtQZmu8iceb7bIepaiMpB3oMXYOVVGKIgHihBhPoRG84FzmQvZSdkP4dAA5W5WpVVsNzduPK21gNtzODaobVBSZYnl9CXZUJgCoGDiR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SOdccR4EinL9mq4uYgngsdIf5oeNdn5jQpcuH8DVYs5FeW9IPFeQhhCXuZlLe8cDZI+uTOUtcJmDqYQHn4yeR7s4+Yi5CqBT58kUeF3zlq6lRKeg/VgmyM7ZalgS0tshGA== 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: On Thu, Jan 26, 2023 at 9:27 AM Mel Gorman wrote: > > On Thu, Jan 26, 2023 at 08:10:26AM -0800, Suren Baghdasaryan wrote: > > On Thu, Jan 26, 2023 at 7:10 AM Mel Gorman wrote: > > > > > > On Wed, Jan 25, 2023 at 03:35:51PM -0800, Suren Baghdasaryan wrote: > > > > Replace direct modifications to vma->vm_flags with calls to modifier > > > > functions to be able to track flag changes and to keep vma locking > > > > correctness. > > > > > > > > Signed-off-by: Suren Baghdasaryan > > > > Acked-by: Michal Hocko > > > > > > Acked-by: Mel Gorman > > > > > > Minor comments that are safe to ignore. > > > > > > I think a better name for mod_vm_flags is set_clear_vm_flags to hint that > > > the first flags are to be set and the second flags are to be cleared. > > > For this patch, it doesn't matter, but it might avoid accidental swapping > > > in the future. > > > > > > reset_vm_flags might also be better named as reinit_vma_flags (or > > > vma_flags_reinit). Maybe also encourage the use of [set|clear_mod]_vm_flags > > > where possible in the comment to track exactly what is changing and > > > why. Some cases like userfaultfd just want to clear __VM_UFFD_FLAGS but > > > altering the flow in this patch is inappropriate and error prone. Others > > > such as the infiniband changes and madvise are a lot more complex. > > > > That's a good point, but I don't want people to use mod_vm_flags() for > > the cases when the order of set/clear really matters. In such cases > > set_vm_flags() and clear_vm_flags() should be explicitly used. Maybe > > to make that clear I should add a comment and rewrite the functions > > as: > > > > void mod_vm_flags(vma, set, clear) { > > vma.vm_flags = vma.vm_flags | set & clear; > > } > > > > Offhand, I'm not thinking of a case where that really matters and as they > are not necessarily ordered, it's raising a read flag so yes, it definitely > it needs a comment if the ordering matters. > > > In this patchset it's not that obvious but mod_vm_flags() was really > > introduced in the original per-VMA lock patchset for efficiency to > > avoid taking extra per-VMA locks. A combo of > > set_vm_flags()+clear_vm_flags() would try to retake the same per-VMA > > lock in the second call while mod_vm_flags() takes the lock only once > > and does both operations. > > Ok, that seems fair but still needs a comment on why a mod_vm_flags is > not necessarily equivalent to a set_vm_flags + clear_vm_flags in terms of > correctness if that is indeed the case. > > > Not a huge overhead because we check if the > > lock is already taken and bail out early but still... > > So, would the above modification to mod_vm_flags() address your concern? > > > > My concerns are entirely with the callers, not the implementation. If > someone is modifying a call site using mod_vm_flags, they have to read > through all the preceding logic to ensure the final combination of flags > is valid. It's a code maintenance issue, not a correctness issue. Got it. I'll modify the implementation to make a single assignment and will add a comment to use only when order doesn't matter. Thanks! > > -- > Mel Gorman > SUSE Labs