Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3044310imu; Mon, 19 Nov 2018 09:47:21 -0800 (PST) X-Google-Smtp-Source: AJdET5f5BUZh1XYF5Rb6RZraU7/jbMM6A4ZJTCLR+Dy7hIxb+wC7pwK6stryW7aLgsjwh6r8XeWG X-Received: by 2002:a63:a30a:: with SMTP id s10mr19607060pge.234.1542649641907; Mon, 19 Nov 2018 09:47:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542649641; cv=none; d=google.com; s=arc-20160816; b=jHu0pAuJr+XOxNBPGFaN53NT/0Jq1BhTKew45tJsSFJvj2XMTeY3vftYn8uMTAQxf8 lKcXdMcKbQmddy9DzYRqkl66dLhGz6vs9IabvrbsrYwGz3qs11J+TIxAEenpsveMf7wC +fJ7IYKCvrm4cUmOo2AyR6U++Kqn9ifohLBBMpXcXmQm+s3rPR/pHDflfGf8P47UIYl3 cGP1FrhG16Z/msmUC/8p/8OsGiwD8Pd7ERVPp8yiBNIfCkxWQzB1A2gfDHB+5QtKcM01 O6XM46okx1aY3DJ7qXaTnkP9qESFmZIUfs5v71jVXqnvqA4RxILgEL6ayhUQZpXMLMGx Y60g== 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; bh=wThH5DVcbaDLjDrnvVWP/PLlV04NhUxkrxaoSaUfRlA=; b=CBjNtYzHikiYUx+JNuTegYVgfg+6i7Mg96m9A6v1sLUGeaIwAoUM0nfo7kKw8as1Y6 5Zxfxj++g32MOsTqQH2trUvXR6gtm2TJ31weRzRV8nYUws8c9jzkUZIHQH1egNDlUr0D dAVOZCDAGgelMZjBM2Tt7dHrU4dHgZCGPq4qslydjAlO1EAKBlWu6UbhgqRTGtwX5o4P OAJODe+GKKWij26sgxAfK6adaMgS91o+tI1GPbXpipfvbFQwoNYa30MFx19IeBXY7s5z sced72TQeM8vIwLV73TFrNlPpM0aMw748cKKH8aNtElMcF4aGGuI3fEBeatqp9qQzRNO 44Gw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u5si11891276plj.129.2018.11.19.09.47.06; Mon, 19 Nov 2018 09:47:21 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388828AbeKTDKc (ORCPT + 99 others); Mon, 19 Nov 2018 22:10:32 -0500 Received: from mx2.suse.de ([195.135.220.15]:35580 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2388421AbeKTDKc (ORCPT ); Mon, 19 Nov 2018 22:10:32 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 472CAAF4F; Mon, 19 Nov 2018 16:46:19 +0000 (UTC) Date: Mon, 19 Nov 2018 17:46:18 +0100 From: Michal Hocko To: Vlastimil Babka Cc: Baoquan He , David Hildenbrand , linux-mm@kvack.org, pifang@redhat.com, linux-kernel@vger.kernel.org, akpm@linux-foundation.org, aarcange@redhat.com, Mel Gorman , Hugh Dickins Subject: Re: Memory hotplug softlock issue Message-ID: <20181119164618.GQ22247@dhcp22.suse.cz> References: <20181115131927.GT23831@dhcp22.suse.cz> <20181115133840.GR2653@MiWiFi-R3L-srv> <20181115143204.GV23831@dhcp22.suse.cz> <20181116012433.GU2653@MiWiFi-R3L-srv> <20181116091409.GD14706@dhcp22.suse.cz> <20181119105202.GE18471@MiWiFi-R3L-srv> <20181119124033.GJ22247@dhcp22.suse.cz> <20181119125121.GK22247@dhcp22.suse.cz> <20181119141016.GO22247@dhcp22.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon 19-11-18 17:36:21, Vlastimil Babka wrote: > On 11/19/18 3:10 PM, Michal Hocko wrote: > > On Mon 19-11-18 13:51:21, Michal Hocko wrote: > >> On Mon 19-11-18 13:40:33, Michal Hocko wrote: > >>> How are > >>> we supposed to converge when the swapin code waits for the migration to > >>> finish with the reference count elevated? > > Indeed this looks wrong. How comes we only found this out now? I guess > the race window where refcounts matter is only a part of the whole > migration, where we update the mapping (migrate_page_move_mapping()). > That's before copying contents, flags etc. I guess we simply never found out because most migration callers simply fail after few attempts. The notable exception is memory offline which tries retries until it suceeds or the caller terminates the process by a fatal signal > >> Just to clarify. This is not only about swapin obviously. Any caller of > >> __migration_entry_wait is affected the same way AFAICS. > > > > In other words. Why cannot we do the following? > > > > diff --git a/mm/migrate.c b/mm/migrate.c > > index f7e4bfdc13b7..7ccab29bcf9a 100644 > > --- a/mm/migrate.c > > +++ b/mm/migrate.c > > @@ -324,19 +324,9 @@ void __migration_entry_wait(struct mm_struct *mm, pte_t *ptep, > > goto out; > > > > page = migration_entry_to_page(entry); > > - > > - /* > > - * Once page cache replacement of page migration started, page_count > > - * *must* be zero. And, we don't want to call wait_on_page_locked() > > - * against a page without get_page(). > > - * So, we use get_page_unless_zero(), here. Even failed, page fault > > - * will occur again. > > - */ > > - if (!get_page_unless_zero(page)) > > - goto out; > > pte_unmap_unlock(ptep, ptl); > > - wait_on_page_locked(page); > > - put_page(page); > > + page_lock(page); > > + page_unlock(page); > > So what protects us from locking a page whose refcount dropped to zero? > and is being freed? The checks in freeing path won't be happy about a > stray lock. Nothing really prevents that. But does it matter. The worst that might happen is that we lock a freed or reused page. Who would complain? -- Michal Hocko SUSE Labs