2009-06-10 21:20:19 +08:00
|
|
|
/**************************************************************************
|
|
|
|
*
|
|
|
|
* Copyright (c) 2006-2009 VMware, Inc., Palo Alto, CA., USA
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sub license, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the
|
|
|
|
* next paragraph) shall be included in all copies or substantial portions
|
|
|
|
* of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
|
|
|
|
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
|
|
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
|
|
* USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
**************************************************************************/
|
|
|
|
/*
|
|
|
|
* Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com>
|
|
|
|
*/
|
|
|
|
|
2012-03-17 12:43:50 +08:00
|
|
|
#define pr_fmt(fmt) "[TTM] " fmt
|
|
|
|
|
2009-06-10 21:20:19 +08:00
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/highmem.h>
|
|
|
|
#include <linux/pagemap.h>
|
2011-06-28 07:18:17 +08:00
|
|
|
#include <linux/shmem_fs.h>
|
2009-06-10 21:20:19 +08:00
|
|
|
#include <linux/file.h>
|
|
|
|
#include <linux/swap.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2011-08-31 06:16:33 +08:00
|
|
|
#include <linux/export.h>
|
2012-10-03 01:01:07 +08:00
|
|
|
#include <drm/drm_cache.h>
|
|
|
|
#include <drm/drm_mem_util.h>
|
|
|
|
#include <drm/ttm/ttm_module.h>
|
|
|
|
#include <drm/ttm/ttm_bo_driver.h>
|
|
|
|
#include <drm/ttm/ttm_placement.h>
|
|
|
|
#include <drm/ttm/ttm_page_alloc.h>
|
2009-06-10 21:20:19 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocates storage for pointers to the pages that back the ttm.
|
|
|
|
*/
|
|
|
|
static void ttm_tt_alloc_page_directory(struct ttm_tt *ttm)
|
|
|
|
{
|
2011-11-10 06:15:26 +08:00
|
|
|
ttm->pages = drm_calloc_large(ttm->num_pages, sizeof(void*));
|
2009-06-10 21:20:19 +08:00
|
|
|
}
|
|
|
|
|
2011-11-10 06:15:26 +08:00
|
|
|
static void ttm_dma_tt_alloc_page_directory(struct ttm_dma_tt *ttm)
|
2009-06-10 21:20:19 +08:00
|
|
|
{
|
2014-08-04 17:28:54 +08:00
|
|
|
ttm->ttm.pages = drm_calloc_large(ttm->ttm.num_pages,
|
|
|
|
sizeof(*ttm->ttm.pages) +
|
2016-09-16 17:32:26 +08:00
|
|
|
sizeof(*ttm->dma_address));
|
|
|
|
ttm->dma_address = (void *) (ttm->ttm.pages + ttm->ttm.num_pages);
|
2009-06-10 21:20:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_X86
|
|
|
|
static inline int ttm_tt_set_page_caching(struct page *p,
|
2010-02-20 05:30:15 +08:00
|
|
|
enum ttm_caching_state c_old,
|
|
|
|
enum ttm_caching_state c_new)
|
2009-06-10 21:20:19 +08:00
|
|
|
{
|
2010-01-13 01:49:43 +08:00
|
|
|
int ret = 0;
|
|
|
|
|
2009-06-10 21:20:19 +08:00
|
|
|
if (PageHighMem(p))
|
|
|
|
return 0;
|
|
|
|
|
2010-02-20 05:30:15 +08:00
|
|
|
if (c_old != tt_cached) {
|
2010-01-13 01:49:43 +08:00
|
|
|
/* p isn't in the default caching state, set it to
|
|
|
|
* writeback first to free its current memtype. */
|
|
|
|
|
|
|
|
ret = set_pages_wb(p, 1);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2009-06-10 21:20:19 +08:00
|
|
|
}
|
2010-01-13 01:49:43 +08:00
|
|
|
|
2010-02-20 05:30:15 +08:00
|
|
|
if (c_new == tt_wc)
|
2010-01-13 01:49:43 +08:00
|
|
|
ret = set_memory_wc((unsigned long) page_address(p), 1);
|
2010-02-20 05:30:15 +08:00
|
|
|
else if (c_new == tt_uncached)
|
2010-01-13 01:49:43 +08:00
|
|
|
ret = set_pages_uc(p, 1);
|
|
|
|
|
|
|
|
return ret;
|
2009-06-10 21:20:19 +08:00
|
|
|
}
|
|
|
|
#else /* CONFIG_X86 */
|
|
|
|
static inline int ttm_tt_set_page_caching(struct page *p,
|
2010-02-20 05:30:15 +08:00
|
|
|
enum ttm_caching_state c_old,
|
|
|
|
enum ttm_caching_state c_new)
|
2009-06-10 21:20:19 +08:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_X86 */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Change caching policy for the linear kernel map
|
|
|
|
* for range of pages in a ttm.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int ttm_tt_set_caching(struct ttm_tt *ttm,
|
|
|
|
enum ttm_caching_state c_state)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
struct page *cur_page;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (ttm->caching_state == c_state)
|
|
|
|
return 0;
|
|
|
|
|
2010-04-01 20:44:57 +08:00
|
|
|
if (ttm->state == tt_unpopulated) {
|
|
|
|
/* Change caching but don't populate */
|
|
|
|
ttm->caching_state = c_state;
|
|
|
|
return 0;
|
2009-06-10 21:20:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ttm->caching_state == tt_cached)
|
2009-08-27 07:53:47 +08:00
|
|
|
drm_clflush_pages(ttm->pages, ttm->num_pages);
|
2009-06-10 21:20:19 +08:00
|
|
|
|
|
|
|
for (i = 0; i < ttm->num_pages; ++i) {
|
|
|
|
cur_page = ttm->pages[i];
|
|
|
|
if (likely(cur_page != NULL)) {
|
2010-02-20 05:30:15 +08:00
|
|
|
ret = ttm_tt_set_page_caching(cur_page,
|
|
|
|
ttm->caching_state,
|
|
|
|
c_state);
|
2009-06-10 21:20:19 +08:00
|
|
|
if (unlikely(ret != 0))
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ttm->caching_state = c_state;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_err:
|
|
|
|
for (j = 0; j < i; ++j) {
|
|
|
|
cur_page = ttm->pages[j];
|
|
|
|
if (likely(cur_page != NULL)) {
|
2010-02-20 05:30:15 +08:00
|
|
|
(void)ttm_tt_set_page_caching(cur_page, c_state,
|
2009-06-10 21:20:19 +08:00
|
|
|
ttm->caching_state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ttm_tt_set_placement_caching(struct ttm_tt *ttm, uint32_t placement)
|
|
|
|
{
|
|
|
|
enum ttm_caching_state state;
|
|
|
|
|
|
|
|
if (placement & TTM_PL_FLAG_WC)
|
|
|
|
state = tt_wc;
|
|
|
|
else if (placement & TTM_PL_FLAG_UNCACHED)
|
|
|
|
state = tt_uncached;
|
|
|
|
else
|
|
|
|
state = tt_cached;
|
|
|
|
|
|
|
|
return ttm_tt_set_caching(ttm, state);
|
|
|
|
}
|
2009-10-30 11:31:26 +08:00
|
|
|
EXPORT_SYMBOL(ttm_tt_set_placement_caching);
|
2009-06-10 21:20:19 +08:00
|
|
|
|
|
|
|
void ttm_tt_destroy(struct ttm_tt *ttm)
|
|
|
|
{
|
2016-06-06 16:17:51 +08:00
|
|
|
if (ttm == NULL)
|
2009-06-10 21:20:19 +08:00
|
|
|
return;
|
|
|
|
|
2016-07-21 18:18:19 +08:00
|
|
|
ttm_tt_unbind(ttm);
|
2009-06-10 21:20:19 +08:00
|
|
|
|
2014-01-03 18:47:23 +08:00
|
|
|
if (ttm->state == tt_unbound)
|
|
|
|
ttm_tt_unpopulate(ttm);
|
2009-06-10 21:20:19 +08:00
|
|
|
|
2011-04-04 07:25:18 +08:00
|
|
|
if (!(ttm->page_flags & TTM_PAGE_FLAG_PERSISTENT_SWAP) &&
|
2009-06-10 21:20:19 +08:00
|
|
|
ttm->swap_storage)
|
|
|
|
fput(ttm->swap_storage);
|
|
|
|
|
2011-11-02 08:46:13 +08:00
|
|
|
ttm->swap_storage = NULL;
|
|
|
|
ttm->func->destroy(ttm);
|
2009-06-10 21:20:19 +08:00
|
|
|
}
|
|
|
|
|
2011-11-02 08:46:13 +08:00
|
|
|
int ttm_tt_init(struct ttm_tt *ttm, struct ttm_bo_device *bdev,
|
|
|
|
unsigned long size, uint32_t page_flags,
|
|
|
|
struct page *dummy_read_page)
|
2009-06-10 21:20:19 +08:00
|
|
|
{
|
2011-11-02 08:46:13 +08:00
|
|
|
ttm->bdev = bdev;
|
2009-08-18 22:51:56 +08:00
|
|
|
ttm->glob = bdev->glob;
|
2009-06-10 21:20:19 +08:00
|
|
|
ttm->num_pages = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
|
|
|
|
ttm->caching_state = tt_cached;
|
|
|
|
ttm->page_flags = page_flags;
|
|
|
|
ttm->dummy_read_page = dummy_read_page;
|
2011-11-02 08:46:13 +08:00
|
|
|
ttm->state = tt_unpopulated;
|
2012-01-04 06:37:37 +08:00
|
|
|
ttm->swap_storage = NULL;
|
2009-06-10 21:20:19 +08:00
|
|
|
|
|
|
|
ttm_tt_alloc_page_directory(ttm);
|
2011-11-10 06:15:26 +08:00
|
|
|
if (!ttm->pages) {
|
2009-06-10 21:20:19 +08:00
|
|
|
ttm_tt_destroy(ttm);
|
2012-03-17 12:43:50 +08:00
|
|
|
pr_err("Failed allocating page table\n");
|
2011-11-02 08:46:13 +08:00
|
|
|
return -ENOMEM;
|
2009-06-10 21:20:19 +08:00
|
|
|
}
|
2011-11-02 08:46:13 +08:00
|
|
|
return 0;
|
2009-06-10 21:20:19 +08:00
|
|
|
}
|
2011-11-02 08:46:13 +08:00
|
|
|
EXPORT_SYMBOL(ttm_tt_init);
|
2009-06-10 21:20:19 +08:00
|
|
|
|
2011-11-10 06:15:26 +08:00
|
|
|
void ttm_tt_fini(struct ttm_tt *ttm)
|
|
|
|
{
|
|
|
|
drm_free_large(ttm->pages);
|
|
|
|
ttm->pages = NULL;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ttm_tt_fini);
|
|
|
|
|
|
|
|
int ttm_dma_tt_init(struct ttm_dma_tt *ttm_dma, struct ttm_bo_device *bdev,
|
|
|
|
unsigned long size, uint32_t page_flags,
|
|
|
|
struct page *dummy_read_page)
|
|
|
|
{
|
|
|
|
struct ttm_tt *ttm = &ttm_dma->ttm;
|
|
|
|
|
|
|
|
ttm->bdev = bdev;
|
|
|
|
ttm->glob = bdev->glob;
|
|
|
|
ttm->num_pages = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
|
|
|
|
ttm->caching_state = tt_cached;
|
|
|
|
ttm->page_flags = page_flags;
|
|
|
|
ttm->dummy_read_page = dummy_read_page;
|
|
|
|
ttm->state = tt_unpopulated;
|
2012-01-04 06:37:37 +08:00
|
|
|
ttm->swap_storage = NULL;
|
2011-11-10 06:15:26 +08:00
|
|
|
|
|
|
|
INIT_LIST_HEAD(&ttm_dma->pages_list);
|
|
|
|
ttm_dma_tt_alloc_page_directory(ttm_dma);
|
2014-08-04 17:28:54 +08:00
|
|
|
if (!ttm->pages) {
|
2011-11-10 06:15:26 +08:00
|
|
|
ttm_tt_destroy(ttm);
|
2012-03-17 12:43:50 +08:00
|
|
|
pr_err("Failed allocating page table\n");
|
2011-11-10 06:15:26 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ttm_dma_tt_init);
|
|
|
|
|
|
|
|
void ttm_dma_tt_fini(struct ttm_dma_tt *ttm_dma)
|
|
|
|
{
|
|
|
|
struct ttm_tt *ttm = &ttm_dma->ttm;
|
|
|
|
|
|
|
|
drm_free_large(ttm->pages);
|
|
|
|
ttm->pages = NULL;
|
|
|
|
ttm_dma->dma_address = NULL;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ttm_dma_tt_fini);
|
|
|
|
|
2009-06-10 21:20:19 +08:00
|
|
|
void ttm_tt_unbind(struct ttm_tt *ttm)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (ttm->state == tt_bound) {
|
2011-11-02 08:46:13 +08:00
|
|
|
ret = ttm->func->unbind(ttm);
|
2009-06-10 21:20:19 +08:00
|
|
|
BUG_ON(ret);
|
|
|
|
ttm->state = tt_unbound;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int ttm_tt_bind(struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (!ttm)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (ttm->state == tt_bound)
|
|
|
|
return 0;
|
|
|
|
|
2011-11-03 11:59:28 +08:00
|
|
|
ret = ttm->bdev->driver->ttm_tt_populate(ttm);
|
2009-06-10 21:20:19 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2011-11-02 08:46:13 +08:00
|
|
|
ret = ttm->func->bind(ttm, bo_mem);
|
2010-10-29 16:46:49 +08:00
|
|
|
if (unlikely(ret != 0))
|
2009-06-10 21:20:19 +08:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
ttm->state = tt_bound;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ttm_tt_bind);
|
|
|
|
|
2011-11-03 11:59:28 +08:00
|
|
|
int ttm_tt_swapin(struct ttm_tt *ttm)
|
2009-06-10 21:20:19 +08:00
|
|
|
{
|
|
|
|
struct address_space *swap_space;
|
|
|
|
struct file *swap_storage;
|
|
|
|
struct page *from_page;
|
|
|
|
struct page *to_page;
|
|
|
|
int i;
|
2010-02-20 10:22:21 +08:00
|
|
|
int ret = -ENOMEM;
|
2009-06-10 21:20:19 +08:00
|
|
|
|
|
|
|
swap_storage = ttm->swap_storage;
|
|
|
|
BUG_ON(swap_storage == NULL);
|
|
|
|
|
2015-12-05 12:45:44 +08:00
|
|
|
swap_space = swap_storage->f_mapping;
|
2009-06-10 21:20:19 +08:00
|
|
|
|
|
|
|
for (i = 0; i < ttm->num_pages; ++i) {
|
2011-06-28 07:18:17 +08:00
|
|
|
from_page = shmem_read_mapping_page(swap_space, i);
|
2010-02-20 10:22:21 +08:00
|
|
|
if (IS_ERR(from_page)) {
|
|
|
|
ret = PTR_ERR(from_page);
|
2009-06-10 21:20:19 +08:00
|
|
|
goto out_err;
|
2010-02-20 10:22:21 +08:00
|
|
|
}
|
2011-11-03 11:59:28 +08:00
|
|
|
to_page = ttm->pages[i];
|
2009-06-10 21:20:19 +08:00
|
|
|
if (unlikely(to_page == NULL))
|
|
|
|
goto out_err;
|
|
|
|
|
2012-09-25 19:57:02 +08:00
|
|
|
copy_highpage(to_page, from_page);
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 20:29:47 +08:00
|
|
|
put_page(from_page);
|
2009-06-10 21:20:19 +08:00
|
|
|
}
|
|
|
|
|
2011-04-04 07:25:18 +08:00
|
|
|
if (!(ttm->page_flags & TTM_PAGE_FLAG_PERSISTENT_SWAP))
|
2009-06-10 21:20:19 +08:00
|
|
|
fput(swap_storage);
|
|
|
|
ttm->swap_storage = NULL;
|
|
|
|
ttm->page_flags &= ~TTM_PAGE_FLAG_SWAPPED;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
out_err:
|
2010-02-20 10:22:21 +08:00
|
|
|
return ret;
|
2009-06-10 21:20:19 +08:00
|
|
|
}
|
|
|
|
|
2011-04-04 07:25:18 +08:00
|
|
|
int ttm_tt_swapout(struct ttm_tt *ttm, struct file *persistent_swap_storage)
|
2009-06-10 21:20:19 +08:00
|
|
|
{
|
|
|
|
struct address_space *swap_space;
|
|
|
|
struct file *swap_storage;
|
|
|
|
struct page *from_page;
|
|
|
|
struct page *to_page;
|
|
|
|
int i;
|
2010-02-20 10:22:21 +08:00
|
|
|
int ret = -ENOMEM;
|
2009-06-10 21:20:19 +08:00
|
|
|
|
|
|
|
BUG_ON(ttm->state != tt_unbound && ttm->state != tt_unpopulated);
|
|
|
|
BUG_ON(ttm->caching_state != tt_cached);
|
|
|
|
|
2011-04-04 07:25:18 +08:00
|
|
|
if (!persistent_swap_storage) {
|
2009-06-10 21:20:19 +08:00
|
|
|
swap_storage = shmem_file_setup("ttm swap",
|
|
|
|
ttm->num_pages << PAGE_SHIFT,
|
|
|
|
0);
|
2015-07-31 16:38:24 +08:00
|
|
|
if (IS_ERR(swap_storage)) {
|
2012-03-17 12:43:50 +08:00
|
|
|
pr_err("Failed allocating swap storage\n");
|
2010-02-20 10:22:21 +08:00
|
|
|
return PTR_ERR(swap_storage);
|
2009-06-10 21:20:19 +08:00
|
|
|
}
|
|
|
|
} else
|
2011-04-04 07:25:18 +08:00
|
|
|
swap_storage = persistent_swap_storage;
|
2009-06-10 21:20:19 +08:00
|
|
|
|
2015-12-05 12:45:44 +08:00
|
|
|
swap_space = swap_storage->f_mapping;
|
2009-06-10 21:20:19 +08:00
|
|
|
|
|
|
|
for (i = 0; i < ttm->num_pages; ++i) {
|
|
|
|
from_page = ttm->pages[i];
|
|
|
|
if (unlikely(from_page == NULL))
|
|
|
|
continue;
|
2011-06-28 07:18:17 +08:00
|
|
|
to_page = shmem_read_mapping_page(swap_space, i);
|
2015-07-31 16:38:24 +08:00
|
|
|
if (IS_ERR(to_page)) {
|
2010-02-20 10:22:21 +08:00
|
|
|
ret = PTR_ERR(to_page);
|
2009-06-10 21:20:19 +08:00
|
|
|
goto out_err;
|
2010-02-20 10:22:21 +08:00
|
|
|
}
|
2012-09-25 19:57:02 +08:00
|
|
|
copy_highpage(to_page, from_page);
|
2009-06-10 21:20:19 +08:00
|
|
|
set_page_dirty(to_page);
|
|
|
|
mark_page_accessed(to_page);
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 20:29:47 +08:00
|
|
|
put_page(to_page);
|
2009-06-10 21:20:19 +08:00
|
|
|
}
|
|
|
|
|
2014-01-03 18:47:23 +08:00
|
|
|
ttm_tt_unpopulate(ttm);
|
2009-06-10 21:20:19 +08:00
|
|
|
ttm->swap_storage = swap_storage;
|
|
|
|
ttm->page_flags |= TTM_PAGE_FLAG_SWAPPED;
|
2011-04-04 07:25:18 +08:00
|
|
|
if (persistent_swap_storage)
|
|
|
|
ttm->page_flags |= TTM_PAGE_FLAG_PERSISTENT_SWAP;
|
2009-06-10 21:20:19 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
out_err:
|
2011-04-04 07:25:18 +08:00
|
|
|
if (!persistent_swap_storage)
|
2009-06-10 21:20:19 +08:00
|
|
|
fput(swap_storage);
|
|
|
|
|
2010-02-20 10:22:21 +08:00
|
|
|
return ret;
|
2009-06-10 21:20:19 +08:00
|
|
|
}
|
2014-01-03 18:47:23 +08:00
|
|
|
|
|
|
|
static void ttm_tt_clear_mapping(struct ttm_tt *ttm)
|
|
|
|
{
|
|
|
|
pgoff_t i;
|
|
|
|
struct page **page = ttm->pages;
|
|
|
|
|
2014-02-05 16:18:26 +08:00
|
|
|
if (ttm->page_flags & TTM_PAGE_FLAG_SG)
|
|
|
|
return;
|
|
|
|
|
2014-01-03 18:47:23 +08:00
|
|
|
for (i = 0; i < ttm->num_pages; ++i) {
|
|
|
|
(*page)->mapping = NULL;
|
|
|
|
(*page++)->index = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ttm_tt_unpopulate(struct ttm_tt *ttm)
|
|
|
|
{
|
|
|
|
if (ttm->state == tt_unpopulated)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ttm_tt_clear_mapping(ttm);
|
|
|
|
ttm->bdev->driver->ttm_tt_unpopulate(ttm);
|
|
|
|
}
|