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 7BC82C4332F for ; Fri, 11 Feb 2022 16:45:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0365B6B0078; Fri, 11 Feb 2022 11:45:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F00566B007B; Fri, 11 Feb 2022 11:45:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DC9396B007D; Fri, 11 Feb 2022 11:45:29 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0222.hostedemail.com [216.40.44.222]) by kanga.kvack.org (Postfix) with ESMTP id C94C46B0078 for ; Fri, 11 Feb 2022 11:45:29 -0500 (EST) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 7A922181AC9CC for ; Fri, 11 Feb 2022 16:45:29 +0000 (UTC) X-FDA: 79131074778.08.A226ECC Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf08.hostedemail.com (Postfix) with ESMTP id B1D82160008 for ; Fri, 11 Feb 2022 16:45:28 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 37F1D210E2; Fri, 11 Feb 2022 16:45:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1644597927; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JG6VCjeiAkeUL6Rpz2LpHri59dxNDgRuJeCG5zsYiLw=; b=c+bwZ0OXGT0PuuChKSsjvdI2ZwQGyZUoSx8Y+jlbLt0Lmme4ZOZ4Wlr8U9wTbcwB+VHCJ3 hXBIA43sdeTPtwcBN5bB/cSef7K387eqIGQ9vjAjHFudxnp2C9PPJRgCmpSOvk+eYx1+m3 ayC+yq4dPnPS1i9xm1nnOOhiyf82oJk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1644597927; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JG6VCjeiAkeUL6Rpz2LpHri59dxNDgRuJeCG5zsYiLw=; b=KF+weUUfsrjBr/2qs5X4rNiVuE8C6g+q4n2SDEBVfvfZM0DFXmKI4GjYsqvmeivgmu9sxj 925HVhAQHm+tosCQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id EDC7313C9E; Fri, 11 Feb 2022 16:45:26 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ppodOaaSBmKydAAAMHmgww (envelope-from ); Fri, 11 Feb 2022 16:45:26 +0000 Message-ID: <2ec49f65-fe4e-26a0-4059-c18e6dab0af4@suse.cz> Date: Fri, 11 Feb 2022 17:45:26 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.1 Subject: Re: [PATCH 07/13] mm/munlock: mlock_pte_range() when mlocking or munlocking Content-Language: en-US To: Hugh Dickins , Andrew Morton Cc: Michal Hocko , "Kirill A. Shutemov" , Matthew Wilcox , David Hildenbrand , Alistair Popple , Johannes Weiner , Rik van Riel , Suren Baghdasaryan , Yu Zhao , Greg Thelen , Shakeel Butt , linux-kernel@vger.kernel.org, linux-mm@kvack.org References: <8e4356d-9622-a7f0-b2c-f116b5f2efea@google.com> <8bc3ee8c-7f1-d812-7f22-4f9f6d436bc@google.com> From: Vlastimil Babka In-Reply-To: <8bc3ee8c-7f1-d812-7f22-4f9f6d436bc@google.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: B1D82160008 X-Stat-Signature: duzrs9dkqf6p1yx7up1njrkgh3kbrfw5 X-Rspam-User: Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=c+bwZ0OX; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=KF+weUUf; spf=pass (imf08.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none X-Rspamd-Server: rspam06 X-HE-Tag: 1644597928-210286 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 2/6/22 22:42, Hugh Dickins wrote: > Fill in missing pieces: reimplementation of munlock_vma_pages_range(), > required to lower the mlock_counts when munlocking without munmapping; > and its complement, implementation of mlock_vma_pages_range(), required > to raise the mlock_counts on pages already there when a range is mlocked. > > Combine them into just the one function mlock_vma_pages_range(), using > walk_page_range() to run mlock_pte_range(). This approach fixes the > "Very slow unlockall()" of unpopulated PROT_NONE areas, reported in > https://lore.kernel.org/linux-mm/70885d37-62b7-748b-29df-9e94f3291736@gmail.com/ > > Munlock clears VM_LOCKED at the start, under exclusive mmap_lock; but if > a racing truncate or holepunch (depending on i_mmap_rwsem) gets to the > pte first, it will not try to munlock the page: leaving release_pages() > to correct it when the last reference to the page is gone - that's okay, > a page is not evictable anyway while it is held by an extra reference. > > Mlock sets VM_LOCKED at the start, under exclusive mmap_lock; but if > a racing remove_migration_pte() or try_to_unmap_one() (depending on > i_mmap_rwsem) gets to the pte first, it will try to mlock the page, > then mlock_pte_range() mlock it a second time. This is harder to > reproduce, but a more serious race because it could leave the page > unevictable indefinitely though the area is munlocked afterwards. > Guard against it by setting the (inappropriate) VM_IO flag, > and modifying mlock_vma_page() to decline such vmas. > > Signed-off-by: Hugh Dickins Acked-by: Vlastimil Babka > @@ -162,8 +230,7 @@ static int mlock_fixup(struct vm_area_struct *vma, struct vm_area_struct **prev, > pgoff_t pgoff; > int nr_pages; > int ret = 0; > - int lock = !!(newflags & VM_LOCKED); > - vm_flags_t old_flags = vma->vm_flags; > + vm_flags_t oldflags = vma->vm_flags; > > if (newflags == vma->vm_flags || (vma->vm_flags & VM_SPECIAL) || Nit: can use oldflags instead of vma->vm_flags above?