From patchwork Fri Sep 30 19:52:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Geffon X-Patchwork-Id: 12995942 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 4DA26C433FE for ; Fri, 30 Sep 2022 19:52:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C1F2E8D0003; Fri, 30 Sep 2022 15:52:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BCD818D0002; Fri, 30 Sep 2022 15:52:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A6E018D0003; Fri, 30 Sep 2022 15:52:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 974698D0002 for ; Fri, 30 Sep 2022 15:52:19 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 62DC8C04AE for ; Fri, 30 Sep 2022 19:52:19 +0000 (UTC) X-FDA: 79969798398.07.DBD8C01 Received: from mail-il1-f201.google.com (mail-il1-f201.google.com [209.85.166.201]) by imf06.hostedemail.com (Postfix) with ESMTP id EF33F180008 for ; Fri, 30 Sep 2022 19:52:18 +0000 (UTC) Received: by mail-il1-f201.google.com with SMTP id g3-20020a056e021a2300b002f875de24a2so4166960ile.6 for ; Fri, 30 Sep 2022 12:52:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date; bh=M+0FjOXGxdUyOWeiIKmnYqXrvtkV45XJ57lTF7hku5U=; b=OHjxPF0CBcbVcOGxJ6AfkBgP6ehzsTThmZ1tBnO5VAvOPc1o4N2O4UzFZ6KdCnVhUh jiqFmBY79+eRtCKZrKru5khB16VvhFMG8QpkgMFmR1XNITxRjHFJC1Z29n5p4cOuq2HF EL9Le0jLEloNqQ/DMh9C7xPTiTd8T8RHqv2LOtfowtqePlaPOfOOeo1CCMnSC4ZFFtea 6GB4WV5qwMWjQC2awnhV47b50YV6ER30wgkKPSq09U4byiuxtq1KxJwTPAgbz3FeSzEL cs6hyV0ngnWWbEzFf3dG/E+qMuTwWUiJzzaMGKeZjBYqLfvyZKxkkhZ7aDHn8O8EpDhS PKvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date; bh=M+0FjOXGxdUyOWeiIKmnYqXrvtkV45XJ57lTF7hku5U=; b=l3mVlLAzmz8yA95B/9hRfVsMNBYKSG/tg64Bm+UsLCgV7eK9BT3O3s+RsscVBrVc68 paKWi86xn6+SMxCbxGX3HquekmwzgpWhQZqD2NSiKUuX+DvtC7eT+0K8PYlVQ+VfSrYR jT/hyDBKaqt10BvETx8ceIJQVpj/mUd2mi4dkQHrR8VpOi8JpqyZZdXpq9md6X16pmKj 6lvx8W4aYl1V+71UxlWHqJlluy7V4VcR6agEU/mI2VvkpDH5qWd3JTewNmirouH4S4ET dtVr26gxi/CHurHCO48yijhQ5pfGSmtqx6ygMlaxhyXL/ufkDQqfo19DwecQzaN2PFiu lLjw== X-Gm-Message-State: ACrzQf0xbXiOPc/02/CE2Hmu7bWwnnTKhsYO8enrOXCZ+aDWHmikxy5V jdr1ftL1owDMQf+ZenhAMZ4onC8bKkAe X-Google-Smtp-Source: AMsMyM6KeFXwgfL1YORHVcKAI+/tHDmnV7aLNPCd0P/jHf5mS+U+kAwFNGyj4hBsx5SqaOiN4dxOa2+nFjRq X-Received: from bg.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:1b4]) (user=bgeffon job=sendgmr) by 2002:a05:6638:3043:b0:341:d8a4:73e8 with SMTP id u3-20020a056638304300b00341d8a473e8mr5584265jak.239.1664567538267; Fri, 30 Sep 2022 12:52:18 -0700 (PDT) Date: Fri, 30 Sep 2022 15:52:15 -0400 In-Reply-To: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog Message-ID: <20220930195215.2360317-1-bgeffon@google.com> Subject: [PATCH] zram: Always expose rw_page From: Brian Geffon To: Andrew Morton Cc: Minchan Kim , Nitin Gupta , Sergey Senozhatsky , linux-kernel@vger.kernel.org, Suleiman Souhlal , Rom Lemarchand , linux-mm@kvack.org, Brian Geffon ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=OHjxPF0C; spf=pass (imf06.hostedemail.com: domain of 38kg3YwcKCIEgljkktslttlqj.htrqnsz2-rrp0fhp.twl@flex--bgeffon.bounces.google.com designates 209.85.166.201 as permitted sender) smtp.mailfrom=38kg3YwcKCIEgljkktslttlqj.htrqnsz2-rrp0fhp.twl@flex--bgeffon.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664567539; a=rsa-sha256; cv=none; b=hAUBTC6Bw3mh7YRWVhjnWcwnj2ERO9X4kEHwuvMvMH4t25fqpG95ho2v/6R2uVUxZTJqDg 3PxKfZD70rVXs9PhuSd3vFhwvKa8REKDCjRah1j2jzQvXAUyLEKMpkKMWm9B5jPkQRU0F+ cnED3JAPd8KPaCS7JSxSzjX5oTgEq5E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664567539; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=M+0FjOXGxdUyOWeiIKmnYqXrvtkV45XJ57lTF7hku5U=; b=asMcnwSh5Y8vQjzG12I28M0z2tSTt1zZQV2eBCgY9hjOzU96iUYuu2cEyU1ggPOcU96OJ4 NvHus6G3F3iHncCTTu2kA9x3KkuujFVYWzNSdf/Fx5LUxsJN1EDQ6yz7ihCV9wBso4Cxtm PKjLkJNUo082GwNApaRBig1cUY5/LE8= X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: EF33F180008 X-Rspam-User: Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=OHjxPF0C; spf=pass (imf06.hostedemail.com: domain of 38kg3YwcKCIEgljkktslttlqj.htrqnsz2-rrp0fhp.twl@flex--bgeffon.bounces.google.com designates 209.85.166.201 as permitted sender) smtp.mailfrom=38kg3YwcKCIEgljkktslttlqj.htrqnsz2-rrp0fhp.twl@flex--bgeffon.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Stat-Signature: 8ur7dfxm3nk4x1e6mmgke1jqo4jn3mtk X-HE-Tag: 1664567538-819008 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: Currently zram will adjust its fops to a version which does not contain rw_page when a backing device has been assigned. This is done to prevent upper layers from assuming a synchronous operation when a page may have been written back. This forces every operation through bio which has overhead associated with bio_alloc/frees. The code can be simplified to always expose a rw_page method and only in the rare event that a page is written back we instead will return -EOPNOTSUPP forcing the upper layer to fallback to bio. Signed-off-by: Brian Geffon Reviewed-by: Sergey Senozhatsky --- drivers/block/zram/zram_drv.c | 26 +++----------------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 226ea76cc819..b9646886be0f 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -52,9 +52,6 @@ static unsigned int num_devices = 1; static size_t huge_class_size; static const struct block_device_operations zram_devops; -#ifdef CONFIG_ZRAM_WRITEBACK -static const struct block_device_operations zram_wb_devops; -#endif static void zram_free_page(struct zram *zram, size_t index); static int zram_bvec_read(struct zram *zram, struct bio_vec *bvec, @@ -543,17 +540,6 @@ static ssize_t backing_dev_store(struct device *dev, zram->backing_dev = backing_dev; zram->bitmap = bitmap; zram->nr_pages = nr_pages; - /* - * With writeback feature, zram does asynchronous IO so it's no longer - * synchronous device so let's remove synchronous io flag. Othewise, - * upper layer(e.g., swap) could wait IO completion rather than - * (submit and return), which will cause system sluggish. - * Furthermore, when the IO function returns(e.g., swap_readpage), - * upper layer expects IO was done so it could deallocate the page - * freely but in fact, IO is going on so finally could cause - * use-after-free when the IO is really done. - */ - zram->disk->fops = &zram_wb_devops; up_write(&zram->init_lock); pr_info("setup backing device %s\n", file_name); @@ -1267,6 +1253,9 @@ static int __zram_bvec_read(struct zram *zram, struct page *page, u32 index, struct bio_vec bvec; zram_slot_unlock(zram, index); + /* If we don't have a bio we came via rw_page, we must fallback to bio */ + if (!bio) + return -EOPNOTSUPP; bvec.bv_page = page; bvec.bv_len = PAGE_SIZE; @@ -1848,15 +1837,6 @@ static const struct block_device_operations zram_devops = { .owner = THIS_MODULE }; -#ifdef CONFIG_ZRAM_WRITEBACK -static const struct block_device_operations zram_wb_devops = { - .open = zram_open, - .submit_bio = zram_submit_bio, - .swap_slot_free_notify = zram_slot_free_notify, - .owner = THIS_MODULE -}; -#endif - static DEVICE_ATTR_WO(compact); static DEVICE_ATTR_RW(disksize); static DEVICE_ATTR_RO(initstate);