Received: by 2002:a4f:b056:0:0:0:0:0 with SMTP id m22csp2662376ivi; Tue, 15 Sep 2020 16:02:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzhShnashkN3UKp4mYthmq7igvT8M6DLOVucYUW/wuacGZ/UX09+9PU5NPkK1AkjfGhhSkw X-Received: by 2002:a17:906:288d:: with SMTP id o13mr23251269ejd.195.1600210944998; Tue, 15 Sep 2020 16:02:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600210944; cv=none; d=google.com; s=arc-20160816; b=vaMK8JpQefKLbMe5Tih1pq8O/cYDmfe80Qa19JF9Jrk8ABVutWfz20WNFxaFSRhYtI x+oOz8Yb3YayL0IsQNNIUfxaIvicvgb+wtZywbTemuPMZcPAmxhXHvC2MlJsDmm9MSvK 5H8AnqM5CW4PlEzc3AGZtZLo2IV5m0N/YIEYYqjgFU1r60NJS186Y+eTotOqQpJOqGHC KvV1dySMmO4VAMK1xedYhELSidhEUxdxHtfKYOh4lsRTAdwAOksC8hBt+zCTGsVsyZqV LxfPMc7EP+Epz5fcbErjEUsTtYp/UAxuqd9/98FBRScNIUwAAtUf0Rux8dgPlCtLVudC /Ctw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=efBNWTa9y7/FOXTfe7lL5eY9jKBFY/REZvNQ5CeJVhk=; b=nPkk/ISDCxlhCdG3Xzd+LPgz4vnAkgZLoWWpCjLwe24DRRAUga1+CBOX/DmCL/gl7w dEHVfopslRFiBdrYVmCmKqfDhkN8OwGP8v8RJ1MMYJe2OXTCM5VtrExQ5AjVthpbrdC4 Ew+wgswzJyfh00icqcOYXJM1UGc5laWg2pGX19Oi8wFZFQme1c9oRAVONE/l6a8Xrohx t07F8P3k3Gir4hfrfnemBVrR2kzKtzkqkrUca6nifIBEV7zDvZ5riLIUQDhQ3E/vU3V8 E2eIXuI/688CaAOUlDHol1zpdq8KO+ZDhEBVWz47C401GPhAP5V/Cn0ej42V6nISZmN4 clFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Q3qp7Hro; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r25si12569570edc.505.2020.09.15.16.02.02; Tue, 15 Sep 2020 16:02:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Q3qp7Hro; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727525AbgIOW73 (ORCPT + 99 others); Tue, 15 Sep 2020 18:59:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:33480 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727392AbgIOPFu (ORCPT ); Tue, 15 Sep 2020 11:05:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600182349; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=efBNWTa9y7/FOXTfe7lL5eY9jKBFY/REZvNQ5CeJVhk=; b=Q3qp7HroIcuytHWGxU2RjqP7EhFf1pyNkWB7fnmsQBz6+J0nHsvTZWpX8P0R5/SGXlRiKl IQvdUWfUTMs3tJyZOf7aagvBmew5e8qNkkdRvfK3q65C/XOrO3B57ErRGIAMJFi3GyIS0B +Px6maEQTh92Co8To0ObLGiyF5TMHGo= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-49-BOTlNFqZOl-FFHGdBO-jKA-1; Tue, 15 Sep 2020 11:05:47 -0400 X-MC-Unique: BOTlNFqZOl-FFHGdBO-jKA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BF4AFCD042; Tue, 15 Sep 2020 15:03:54 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.40.192.186]) by smtp.corp.redhat.com (Postfix) with SMTP id 72F995DC08; Tue, 15 Sep 2020 15:03:50 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Tue, 15 Sep 2020 17:03:54 +0200 (CEST) Date: Tue, 15 Sep 2020 17:03:49 +0200 From: Oleg Nesterov To: Peter Xu Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Maya B . Gokhale" , Linus Torvalds , Yang Shi , Marty Mcfadden , Kirill Shutemov , Jann Horn , Jan Kara , Kirill Tkhai , Andrea Arcangeli , Christoph Hellwig , Andrew Morton Subject: Re: [PATCH 1/4] mm: Trial do_wp_page() simplification Message-ID: <20200915150349.GA22415@redhat.com> References: <20200821234958.7896-1-peterx@redhat.com> <20200821234958.7896-2-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200821234958.7896-2-peterx@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 08/21, Peter Xu wrote: > > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -2927,50 +2927,25 @@ static vm_fault_t do_wp_page(struct vm_fault *vmf) > * not dirty accountable. > */ > if (PageAnon(vmf->page)) { > - int total_map_swapcount; > - if (PageKsm(vmf->page) && (PageSwapCache(vmf->page) || > - page_count(vmf->page) != 1)) > + struct page *page = vmf->page; > + > + /* PageKsm() doesn't necessarily raise the page refcount */ > + if (PageKsm(page) || page_count(page) != 1) > + goto copy; > + if (!trylock_page(page)) > + goto copy; > + if (PageKsm(page) || page_mapcount(page) != 1 || page_count(page) != 1) { > + unlock_page(page); > goto copy; > - if (!trylock_page(vmf->page)) { > - get_page(vmf->page); > - pte_unmap_unlock(vmf->pte, vmf->ptl); > - lock_page(vmf->page); > - vmf->pte = pte_offset_map_lock(vma->vm_mm, vmf->pmd, > - vmf->address, &vmf->ptl); > - if (!pte_same(*vmf->pte, vmf->orig_pte)) { > - update_mmu_tlb(vma, vmf->address, vmf->pte); > - unlock_page(vmf->page); > - pte_unmap_unlock(vmf->pte, vmf->ptl); > - put_page(vmf->page); > - return 0; > - } > - put_page(vmf->page); > - } > - if (PageKsm(vmf->page)) { > - bool reused = reuse_ksm_page(vmf->page, vmf->vma, > - vmf->address); > - unlock_page(vmf->page); > - if (!reused) > - goto copy; > - wp_page_reuse(vmf); > - return VM_FAULT_WRITE; > - } > - if (reuse_swap_page(vmf->page, &total_map_swapcount)) { It seems that nobody else calls reuse_swap_page() with total_map_swapcount != NULL. Oleg.