diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2013-05-08 14:51:05 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-05-08 14:51:05 -0400 |
| commit | ebb37277796269da36a8bc5d72ed1e8e1fb7d34b (patch) | |
| tree | 0ded627a62a5cec70b18d12825dd858855c135d3 /lib | |
| parent | 4de13d7aa8f4d02f4dc99d4609575659f92b3c5a (diff) | |
| parent | f50efd2fdbd9b35b11f5778ed85beb764184bda9 (diff) | |
Merge branch 'for-3.10/drivers' of git://git.kernel.dk/linux-block
Pull block driver updates from Jens Axboe:
"It might look big in volume, but when categorized, not a lot of
drivers are touched. The pull request contains:
- mtip32xx fixes from Micron.
- A slew of drbd updates, this time in a nicer series.
- bcache, a flash/ssd caching framework from Kent.
- Fixes for cciss"
* 'for-3.10/drivers' of git://git.kernel.dk/linux-block: (66 commits)
bcache: Use bd_link_disk_holder()
bcache: Allocator cleanup/fixes
cciss: bug fix to prevent cciss from loading in kdump crash kernel
cciss: add cciss_allow_hpsa module parameter
drivers/block/mg_disk.c: add CONFIG_PM_SLEEP to suspend/resume functions
mtip32xx: Workaround for unaligned writes
bcache: Make sure blocksize isn't smaller than device blocksize
bcache: Fix merge_bvec_fn usage for when it modifies the bvm
bcache: Correctly check against BIO_MAX_PAGES
bcache: Hack around stuff that clones up to bi_max_vecs
bcache: Set ra_pages based on backing device's ra_pages
bcache: Take data offset from the bdev superblock.
mtip32xx: mtip32xx: Disable TRIM support
mtip32xx: fix a smatch warning
bcache: Disable broken btree fuzz tester
bcache: Fix a format string overflow
bcache: Fix a minor memory leak on device teardown
bcache: Documentation updates
bcache: Use WARN_ONCE() instead of __WARN()
bcache: Add missing #include <linux/prefetch.h>
...
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/lru_cache.c | 56 |
1 files changed, 46 insertions, 10 deletions
diff --git a/lib/lru_cache.c b/lib/lru_cache.c index 8335d39d2ccd..4a83ecd03650 100644 --- a/lib/lru_cache.c +++ b/lib/lru_cache.c | |||
| @@ -365,7 +365,13 @@ static int lc_unused_element_available(struct lru_cache *lc) | |||
| 365 | return 0; | 365 | return 0; |
| 366 | } | 366 | } |
| 367 | 367 | ||
| 368 | static struct lc_element *__lc_get(struct lru_cache *lc, unsigned int enr, bool may_change) | 368 | /* used as internal flags to __lc_get */ |
| 369 | enum { | ||
| 370 | LC_GET_MAY_CHANGE = 1, | ||
| 371 | LC_GET_MAY_USE_UNCOMMITTED = 2, | ||
| 372 | }; | ||
| 373 | |||
| 374 | static struct lc_element *__lc_get(struct lru_cache *lc, unsigned int enr, unsigned int flags) | ||
| 369 | { | 375 | { |
| 370 | struct lc_element *e; | 376 | struct lc_element *e; |
| 371 | 377 | ||
| @@ -380,22 +386,31 @@ static struct lc_element *__lc_get(struct lru_cache *lc, unsigned int enr, bool | |||
| 380 | * this enr is currently being pulled in already, | 386 | * this enr is currently being pulled in already, |
| 381 | * and will be available once the pending transaction | 387 | * and will be available once the pending transaction |
| 382 | * has been committed. */ | 388 | * has been committed. */ |
| 383 | if (e && e->lc_new_number == e->lc_number) { | 389 | if (e) { |
| 390 | if (e->lc_new_number != e->lc_number) { | ||
| 391 | /* It has been found above, but on the "to_be_changed" | ||
| 392 | * list, not yet committed. Don't pull it in twice, | ||
| 393 | * wait for the transaction, then try again... | ||
| 394 | */ | ||
| 395 | if (!(flags & LC_GET_MAY_USE_UNCOMMITTED)) | ||
| 396 | RETURN(NULL); | ||
| 397 | /* ... unless the caller is aware of the implications, | ||
| 398 | * probably preparing a cumulative transaction. */ | ||
| 399 | ++e->refcnt; | ||
| 400 | ++lc->hits; | ||
| 401 | RETURN(e); | ||
| 402 | } | ||
| 403 | /* else: lc_new_number == lc_number; a real hit. */ | ||
| 384 | ++lc->hits; | 404 | ++lc->hits; |
| 385 | if (e->refcnt++ == 0) | 405 | if (e->refcnt++ == 0) |
| 386 | lc->used++; | 406 | lc->used++; |
| 387 | list_move(&e->list, &lc->in_use); /* Not evictable... */ | 407 | list_move(&e->list, &lc->in_use); /* Not evictable... */ |
| 388 | RETURN(e); | 408 | RETURN(e); |
| 389 | } | 409 | } |
| 410 | /* e == NULL */ | ||
| 390 | 411 | ||
| 391 | ++lc->misses; | 412 | ++lc->misses; |
| 392 | if (!may_change) | 413 | if (!(flags & LC_GET_MAY_CHANGE)) |
| 393 | RETURN(NULL); | ||
| 394 | |||
| 395 | /* It has been found above, but on the "to_be_changed" list, not yet | ||
| 396 | * committed. Don't pull it in twice, wait for the transaction, then | ||
| 397 | * try again */ | ||
| 398 | if (e) | ||
| 399 | RETURN(NULL); | 414 | RETURN(NULL); |
| 400 | 415 | ||
| 401 | /* To avoid races with lc_try_lock(), first, mark us dirty | 416 | /* To avoid races with lc_try_lock(), first, mark us dirty |
| @@ -477,7 +492,27 @@ static struct lc_element *__lc_get(struct lru_cache *lc, unsigned int enr, bool | |||
| 477 | */ | 492 | */ |
| 478 | struct lc_element *lc_get(struct lru_cache *lc, unsigned int enr) | 493 | struct lc_element *lc_get(struct lru_cache *lc, unsigned int enr) |
| 479 | { | 494 | { |
| 480 | return __lc_get(lc, enr, 1); | 495 | return __lc_get(lc, enr, LC_GET_MAY_CHANGE); |
| 496 | } | ||
| 497 | |||
| 498 | /** | ||
| 499 | * lc_get_cumulative - like lc_get; also finds to-be-changed elements | ||
| 500 | * @lc: the lru cache to operate on | ||
| 501 | * @enr: the label to look up | ||
| 502 | * | ||
| 503 | * Unlike lc_get this also returns the element for @enr, if it is belonging to | ||
| 504 | * a pending transaction, so the return values are like for lc_get(), | ||
| 505 | * plus: | ||
| 506 | * | ||
| 507 | * pointer to an element already on the "to_be_changed" list. | ||
| 508 | * In this case, the cache was already marked %LC_DIRTY. | ||
| 509 | * | ||
| 510 | * Caller needs to make sure that the pending transaction is completed, | ||
| 511 | * before proceeding to actually use this element. | ||
| 512 | */ | ||
| 513 | struct lc_element *lc_get_cumulative(struct lru_cache *lc, unsigned int enr) | ||
| 514 | { | ||
| 515 | return __lc_get(lc, enr, LC_GET_MAY_CHANGE|LC_GET_MAY_USE_UNCOMMITTED); | ||
| 481 | } | 516 | } |
| 482 | 517 | ||
| 483 | /** | 518 | /** |
| @@ -648,3 +683,4 @@ EXPORT_SYMBOL(lc_seq_printf_stats); | |||
| 648 | EXPORT_SYMBOL(lc_seq_dump_details); | 683 | EXPORT_SYMBOL(lc_seq_dump_details); |
| 649 | EXPORT_SYMBOL(lc_try_lock); | 684 | EXPORT_SYMBOL(lc_try_lock); |
| 650 | EXPORT_SYMBOL(lc_is_used); | 685 | EXPORT_SYMBOL(lc_is_used); |
| 686 | EXPORT_SYMBOL(lc_get_cumulative); | ||
