Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp890179pxb; Wed, 13 Jan 2021 19:37:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJxj79H7FYQrKZ6gIUogTrrhBkbdxe+X9HHZK8liG8UeKJ0X69v10nzrV3rLAq2ks5/DYuC1 X-Received: by 2002:a17:906:7804:: with SMTP id u4mr3886561ejm.97.1610595437554; Wed, 13 Jan 2021 19:37:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610595437; cv=none; d=google.com; s=arc-20160816; b=O39JCpB4QH2MERvRqbwQZ9mM3odt/OA6ej9eG2mbjubXg7HEv+HX7pCFsvAcNo/BUa JMlYcrsJh2FoZLJwHm0G79SPrCe+CzrEpyAc26idzndqlAz+mF/joze0dPy2Klf5Cuek KQWOHn7T2o4WkZ7JBsKHqBx94p+zJJ2y+jp4v0686dcARnmMDRK8huZZwYPsIZZajKMi anjQD38u/Z8ey8QO8e2Haw4C26ihu0lThFgff5lvD2BUcDBznVL/y3LwQYTNRchrooyK IUHpFTcEV2TaRtxRUqiM5ArzW/8m6bnr3VJZUwVFChJ1QCTfUKNFjXTvgVJD9qI2mIez 4mzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=M5N5hogdb1VE5N+GuBnvP2hTDvEwQA42F7hxBNyZMt4=; b=Vu1lHcHxJEZtXdHCrOzTx+VM+/vwb0fv6xkiiO6lYdGZti15d6wbzbVdIWfUxQg7xm h1pxY2zYQMyxnVI7CZEnh83H2RQQFHlYpwVnbC5dbDVsmUuOpYRMjeI9rGUJNnB6+LyA JMWQtrbtvrILAjXhTpmHIsaePZT81vMNHV/auco9uL2RdxqDMm0K7rgwQ8GEo8mhFIuE WCrXRAvAsmPfHTKjwXBc1Bkq3quOe1eZ1WDE77+214ZRhVDaY9x0AXbn75WRj8+aCDwP UoYi0Gb06a6BUVgv8gP1MCZ9QxcE/yPkqQI8tH7xtncGhw9A1Ydm58Bc0A3IvxL0UUxd mmDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=FEqCHqMK; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v13si2348973edl.517.2021.01.13.19.36.54; Wed, 13 Jan 2021 19:37:17 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=FEqCHqMK; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727068AbhANDeP (ORCPT + 99 others); Wed, 13 Jan 2021 22:34:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726705AbhANDeO (ORCPT ); Wed, 13 Jan 2021 22:34:14 -0500 Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2AE1C061575 for ; Wed, 13 Jan 2021 19:33:28 -0800 (PST) Received: by mail-pg1-x530.google.com with SMTP id c22so2823163pgg.13 for ; Wed, 13 Jan 2021 19:33:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition; bh=M5N5hogdb1VE5N+GuBnvP2hTDvEwQA42F7hxBNyZMt4=; b=FEqCHqMKatXUgxZo1m9x9XWMmJmnZLrMOpBLIkbng24V512Il3r0ZQNAi5YHI/s2R1 jau3yFgUJELL5UKibd7Q+RdwJfmPO6VUTfxHGI1Fvo3b+OXTuqIXNOKJ9EuXHdWcpsfP Z56E1Z56qn5TiRUlQPzBOzUmZlpSLF9suPKq54/u2GWIMt6H5b/3wla+uMVvIU6MUs2N RhYeiH4AADdHT+10avtmDmWydRpeILPcsagg4Dh7RPBLV5kR0KnjmzyBt1eyMABFzrq6 4Q0IpMrPCVk9hdMawRcOc1y7AaS3gQtK4BSbUAZzVimkJYuwmS2xjK5oW7wu4y5RUAkN QmqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=M5N5hogdb1VE5N+GuBnvP2hTDvEwQA42F7hxBNyZMt4=; b=FD6FE/G8RLqTRwZTUnYuLjQPbBfcfh+9eVLanTp0d00nbAKIRLVTXkeerXA4rs2r30 7NRxh9HxNhFiXyPCdYdxuIxTh4cW2Uh4MlnocdeLSjOMcbLl76OcmR7jY5G2h4yK3EzN z3tCZaOSeqwIjmqdHVaUv+/yc08X5nkMJEFopLe/NWv8O6tmHfNj3d13wTOieUHGZpux i4az17lChKdk4cqofNlAKGWYCsyzHCLR7e66/jANChHe2xrgLKK/cJs2NFnb73dkXXlF V48NXvwAkICt4Gv24Ujd0iENtmWY5AuTPkrMUCLdRHvXhCRcbXCYiOKADpNlC5r24e51 nX2g== X-Gm-Message-State: AOAM5330aor080oLb33IU+0of1Bz66SHPIytNQ82Jadz2ZOO0TBlL9mL YkS+LwzEYdnOd23kdVtEjKg= X-Received: by 2002:a63:f512:: with SMTP id w18mr5354005pgh.154.1610595208352; Wed, 13 Jan 2021 19:33:28 -0800 (PST) Received: from localhost ([100.87.84.221]) by smtp.gmail.com with ESMTPSA id o129sm3611513pfg.66.2021.01.13.19.33.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jan 2021 19:33:27 -0800 (PST) Date: Thu, 14 Jan 2021 12:33:10 +0900 From: Sergey Senozhatsky To: Andrew Morton Cc: Hugh Dickins , "Kirill A. Shutemov" , Suleiman Souhlal , Matthew Wilcox , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: madvise(MADV_REMOVE) deadlocks on shmem THP Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, We are running into lockups during the memory pressure tests on our boards, which essentially NMI panic them. In short the test case is - THP shmem echo advise > /sys/kernel/mm/transparent_hugepage/shmem_enabled - And a user-space process doing madvise(MADV_HUGEPAGE) on new mappings, and madvise(MADV_REMOVE) when it wants to remove the page range The problem boils down to the reverse locking chain: kswapd does lock_page(page) -> down_read(page->mapping->i_mmap_rwsem) madvise() process does down_write(page->mapping->i_mmap_rwsem) -> lock_page(page) CPU0 CPU1 kswapd vfs_fallocate() shrink_node() shmem_fallocate() shrink_active_list() unmap_mapping_range() page_referenced() << lock page:PG_locked >> unmap_mapping_pages() << down_write(mapping->i_mmap_rwsem) >> rmap_walk_file() zap_page_range_single() down_read(mapping->i_mmap_rwsem) << W-locked on CPU1>> unmap_page_range() rwsem_down_read_failed() __split_huge_pmd() __rwsem_down_read_failed_common() __lock_page() << PG_locked on CPU0 >> schedule() wait_on_page_bit_common() io_schedule() -ss