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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8B874C6379F for ; Tue, 14 Feb 2023 19:06:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231186AbjBNTGz (ORCPT ); Tue, 14 Feb 2023 14:06:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229515AbjBNTGx (ORCPT ); Tue, 14 Feb 2023 14:06:53 -0500 Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35659AF; Tue, 14 Feb 2023 11:06:52 -0800 (PST) Received: by mail-pg1-x533.google.com with SMTP id 24so10903367pgt.7; Tue, 14 Feb 2023 11:06:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=tR/3i49sq5hz9XtCZE+PWBTV406btHq8pkhmC0xJBgE=; b=kRXCfHvnVjapwi015b0xlR827EdxddRsUAxsIADH90lYdHsP3qc5xUijELcU47v5DP RKhwxn/KRl3n6lCNAchGzTRGaXFTazeQUYYDaLbgg/4v9jjtNlV+eMiQEkHmKx/ELiMa eFJAbuQ2f2QTiy/inbPj6O3YLNor8m7xNX3yCXP8j5nvVi151z1mZTF5eZzazTvgpplt 2NlX6HDlCapdFRNgDhjHarJCwA0doM2TJJTXcytjM4zFHphszSKaFbrAJNP8xgmk1JLX aKncV6CBNTaSkfXSKXWx/HwNUD/7wIcUMIVjk3jYSkL57Y5VGcRZX00EZL/f3/vhRdHK baXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=tR/3i49sq5hz9XtCZE+PWBTV406btHq8pkhmC0xJBgE=; b=yC6ZxBjsksztdIn7IuAmSNCBwm1bkmAiciRdhkWdbNxyngvJCYhRAYFtzVXU7O6uug 2CkUhLjBL0ZSPGL0BRfeycSWQ612geFGlVtLibnPyplQBACcYV22yARWg+58YNS21stL nw1lctaZi3s6db2BxScsFjy45m8E8kYGOwtmvY6d3gpE/n5yJnDNQ2TaUfZINXAP7UF6 rY+t1x+m/ZefHUO0mdTYWkRvEoUUrtZF5Jb1N8Rvlw0T3zfPa0+jQ4mNQT8gYH69rudF f6j8ZYmfWT3gbhTVU7L0YTzE5FBWSj8UldjClkzfyuspJeU+5bY0cZPOsN42sMBcjr7k m5ew== X-Gm-Message-State: AO0yUKUoLdnIKU/jTW+4o3uFpPJCrchSjs0UXJtr2xkZS5QvJc0nkzSD tczPsINi7FNQ2N011M00+8Q= X-Google-Smtp-Source: AK7set9KDqtSpLuf4DjmW649rLWZQ9WMurHdl9XlWBl5a0mpXl+jxH6VIQhqsW0P4nmezUIMvrdTSQ== X-Received: by 2002:a05:6a00:cf:b0:5a8:ac19:8f42 with SMTP id e15-20020a056a0000cf00b005a8ac198f42mr2623706pfj.14.1676401610866; Tue, 14 Feb 2023 11:06:50 -0800 (PST) Received: from strix-laptop (2001-b011-20e0-1465-11be-7287-d61f-f938.dynamic-ip6.hinet.net. [2001:b011:20e0:1465:11be:7287:d61f:f938]) by smtp.gmail.com with ESMTPSA id n19-20020a62e513000000b005a852450b14sm10172153pff.183.2023.02.14.11.06.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Feb 2023 11:06:50 -0800 (PST) Date: Wed, 15 Feb 2023 03:06:39 +0800 From: Chih-En Lin To: David Hildenbrand Cc: Pasha Tatashin , Andrew Morton , Qi Zheng , "Matthew Wilcox (Oracle)" , Christophe Leroy , John Hubbard , Nadav Amit , Barry Song , Steven Rostedt , Masami Hiramatsu , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Yang Shi , Peter Xu , Vlastimil Babka , Zach O'Keefe , Yun Zhou , Hugh Dickins , Suren Baghdasaryan , Yu Zhao , Juergen Gross , Tong Tiangen , Liu Shixin , Anshuman Khandual , Li kunyu , Minchan Kim , Miaohe Lin , Gautam Menghani , Catalin Marinas , Mark Brown , Will Deacon , Vincenzo Frascino , Thomas Gleixner , "Eric W. Biederman" , Andy Lutomirski , Sebastian Andrzej Siewior , "Liam R. Howlett" , Fenghua Yu , Andrei Vagin , Barret Rhoden , Michal Hocko , "Jason A. Donenfeld" , Alexey Gladkov , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-trace-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Dinglan Peng , Pedro Fonseca , Jim Huang , Huichun Feng Subject: Re: [PATCH v4 00/14] Introduce Copy-On-Write to Page Table Message-ID: References: <20230207035139.272707-1-shiyn.lin@gmail.com> <62c44d12-933d-ee66-ef50-467cd8d30a58@redhat.com> <28f1e75a-a1fc-a172-3628-83575e387f9a@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <28f1e75a-a1fc-a172-3628-83575e387f9a@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 14, 2023 at 06:59:50PM +0100, David Hildenbrand wrote: > On 14.02.23 18:54, Chih-En Lin wrote: > > > > > > > > > (2) break_cow_pte() can fail, which means that we can fail some > > > > > operations (possibly silently halfway through) now. For example, > > > > > looking at your change_pte_range() change, I suspect it's wrong. > > > > > > > > Maybe I should add WARN_ON() and skip the failed COW PTE. > > > > > > One way or the other we'll have to handle it. WARN_ON() sounds wrong for > > > handling OOM situations (e.g., if only that cgroup is OOM). > > > > Or we should do the same thing like you mentioned: > > " > > For example, __split_huge_pmd() is currently not able to report a > > failure. I assume that we could sleep in there. And if we're not able to > > allocate any memory in there (with sleeping), maybe the process should > > be zapped either way by the OOM killer. > > " > > > > But instead of zapping the process, we just skip the failed COW PTE. > > I don't think the user will expect their process to be killed by > > changing the protection. > > The process is consuming more memory than it is capable of consuming. The > process most probably would have died earlier without the PTE optimization. > > But yeah, it all gets tricky ... > > > > > > > > > > > > (3) handle_cow_pte_fault() looks quite complicated and needs quite some > > > > > double-checking: we temporarily clear the PMD, to reset it > > > > > afterwards. I am not sure if that is correct. For example, what > > > > > stops another page fault stumbling over that pmd_none() and > > > > > allocating an empty page table? Maybe there are some locking details > > > > > missing or they are very subtle such that we better document them. I > > > > > recall that THP played quite some tricks to make such cases work ... > > > > > > > > I think that holding mmap_write_lock may be enough (I added > > > > mmap_assert_write_locked() in the fault function btw). But, I might > > > > be wrong. I will look at the THP stuff to see how they work. Thanks. > > > > > > > > > > Ehm, but page faults don't hold the mmap lock writable? And so are other > > > callers, like MADV_DONTNEED or MADV_FREE. > > > > > > handle_pte_fault()->handle_pte_fault()->mmap_assert_write_locked() should > > > bail out. > > > > > > Either I am missing something or you didn't test with lockdep enabled :) > > > > You're right. I thought I enabled the lockdep. > > And, why do I have the page fault will handle the mmap lock writable in my mind. > > The page fault holds the mmap lock readable instead of writable. > > ;-) > > > > I should check/test all the locks again. > > Thanks. > > Note that we have other ways of traversing page tables, especially, using > the rmap which does not hold the mmap lock. Not sure if there are similar > issues when suddenly finding no page table where there logically should be > one. Or when a page table gets replaced and modified, while rmap code still > walks the shared copy. Hm. It seems like I should take carefully for the page table entry in page fault with rmap. ;) While the rmap code walks the page table, it will hold the pt lock. So, maybe I should hold the old (shared) PTE table's lock in handle_cow_pte_fault() all the time. Thanks, Chih-En Lin